Don't send heroes away from the province you're trying to expand into (#2510)

* scripts cleanup logs too

* missed the semicolon

* fix more tests


Former-commit-id: fdde1b0699310b172caf80741ed1a0f39d563185
This commit is contained in:
2023-03-07 19:58:14 -08:00
committed by GitHub
parent de796162f4
commit a21a10d838
7 changed files with 67 additions and 5 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
echo "Remove local files?"
select yn in "Yes" "No"; do
case $yn in
Yes ) rm -rf ~/eagle0/eagle/save/*; rm -rf ~/eagle0/shardok/save/*; break;;
Yes ) rm -rf ~/eagle0/eagle/save/*; rm -rf ~/eagle0/shardok/save/*; rm -rf ~/eagle0/eagle/log/*; break;;
No ) exit;;
esac
done
+1
View File
@@ -99,6 +99,7 @@ scala_library(
"//src/main/scala/net/eagle0/eagle:eagle_pkg",
"//src/main/scala/net/eagle0/eagle/library/util:battalion_utils",
"//src/main/scala/net/eagle0/eagle/library/util:command_selection",
"//src/main/scala/net/eagle0/eagle/library/util:eagle_require",
"//src/main/scala/net/eagle0/eagle/library/util:province_distances",
"//src/main/scala/net/eagle0/eagle/library/util/command_choice_helpers:province_gold_surplus_calculator",
],
@@ -8,6 +8,7 @@ import net.eagle0.eagle.api.available_command.{
import net.eagle0.eagle.api.selected_command.MarchSelectedCommand
import net.eagle0.eagle.common.combat_unit.CombatUnit
import net.eagle0.eagle.internal.game_state.GameState
import net.eagle0.eagle.library.util.EagleRequire.internalRequire
import net.eagle0.eagle.library.util.command_choice_helpers.ProvinceGoldSurplusCalculator.provinceGoldSurplus
import net.eagle0.eagle.library.util.{
BattalionUtils,
@@ -43,6 +44,11 @@ object MarchTowardProvinceCommandChooser {
val actingProvinceId = ac.actingProvinceId
bestCommand.flatMap { case (opmc, dest, _) =>
internalRequire(
opmc.originProvinceId != destinationProvinceId,
s"Marching away from $destinationProvinceId in an effort to get to that province"
)
val originProvince = gs.provinces(opmc.originProvinceId)
val takenHeroIds =
@@ -551,6 +551,7 @@ object MidGameAIClient {
}
}
.minByOption(_._1)
.filterNot(_._1 == 0) // If distance is zero, we'd be moving away from the province we're trying to get to
.map { case (distance: Int, destinationProvinceId: ProvinceId) =>
(
// distance to the faction leader province we're closest to
@@ -225,6 +225,59 @@ class MidGameAIClientTest
commandSelection shouldBe empty
}
"maybeMoveHeroesTowardFactionLeaderCommand" should "not move heroes away from the faction leader" in {
val gs = GameState(
factions = Map(factionId -> faction.withLeaders(Vector(leaderId, 123))),
provinces = IDable.mapifyProvinces(
provinceA
.withRulingHeroId(123)
.withRulingFactionHeroIds(Vector(123, 124, 125, 126, 127, 128))
.withHeroCap(8),
provinceB,
provinceC.withRulingFactionHeroIds(Vector(11)),
provinceD
),
heroes = heroesInLeaderProvince.map(h => h.id -> h).toMap ++ Vector(
11, 12, 13, 14, 123, 124, 125, 126, 127, 128
).map(hid => hid -> Hero(id = hid)).toMap
)
val acs = Vector(
MarchAvailableCommand(
actingProvinceId = 1,
oneProvinceCommands = Vector(
MarchCommandFromOneProvince(
originProvinceId = 1,
availableDestinationProvinces = Vector(2, 3, 4),
availableHeroIds = Vector(123, 124, 125, 126, 127, 128)
),
MarchCommandFromOneProvince(
originProvinceId = 2,
availableDestinationProvinces = Vector(1, 3, 4),
availableHeroIds = Vector(87)
),
MarchCommandFromOneProvince(
originProvinceId = 3,
availableDestinationProvinces = Vector(1, 2),
availableHeroIds = Vector(11, 12, 13, 14),
goldAvailable = 6000,
foodAvailable = 7000
)
)
)
)
val commandSelection =
MidGameAIClient
.maybeMoveHeroesTowardFactionLeaderCommand(
actingFactionId = factionId,
gs = gs,
acs = acs
)
commandSelection shouldBe empty
}
"maybeChosenScoutCommand" should "return nothing if no targets have me as a neighbor" in {
val gameState = GameState(
currentDate = Date(year = 233, month = 8),
@@ -365,13 +365,13 @@ class PerformVassalCommandsPhaseActionTest
.actingProvinceId shouldBe developingProvince.id
}
it should "return a gift command if there are only a couple of heroes with low loyalty" in {
it should "return a gift command if there is only one hero with low loyalty" in {
val developingProvince = actingProvince.withProvinceOrders(DEVELOP)
val developingGS =
gameState.update(
_.provinces(developingProvince.id) := developingProvince,
_.heroes(1).loyalty := 25,
_.heroes(2).loyalty := 20,
_.heroes(1).loyalty := 70,
_.heroes(2).loyalty := 25,
_.heroes(3).loyalty := 70,
_.heroes(4).loyalty := 70,
_.heroes(5).loyalty := 70
@@ -974,7 +974,8 @@ class CommandChoiceHelpersTest
actingFactionId = 3,
actingProvinceId = 7,
available = ac,
selected = TravelSelectedCommand()
selected = TravelSelectedCommand(),
reason = "travel to buy food"
)
)
}