Resolved #469 - AI Great General tries to maximize effect on troops

This commit is contained in:
Yair Morgenstern 2019-03-02 22:53:30 +02:00
parent 2d1a044e29
commit 9e5d6d3c75
5 changed files with 170 additions and 165 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 885 KiB

After

Width:  |  Height:  |  Size: 879 KiB

View File

@ -17,7 +17,7 @@ class UnCivGame : Game() {
* This exists so that when debugging we can see the entire map. * This exists so that when debugging we can see the entire map.
* Remember to turn this to false before commit and upload! * Remember to turn this to false before commit and upload!
*/ */
val viewEntireMapForDebug = false val viewEntireMapForDebug = true
// For when you need to test something in an advanced game and don't have time to faff around // For when you need to test something in an advanced game and don't have time to faff around
val superchargedForDebug = false val superchargedForDebug = false

View File

@ -31,7 +31,7 @@ class UnitAutomation{
} }
if (unit.name == "Great General") if (unit.name == "Great General")
return SpecificUnitAutomation().automateGeneral(unit) return SpecificUnitAutomation().automateGreatGeneral(unit)
if(unit.name.startsWith("Great") if(unit.name.startsWith("Great")
&& unit.name in GreatPersonManager().statToGreatPersonMapping.values){ // So "Great War Infantry" isn't caught here && unit.name in GreatPersonManager().statToGreatPersonMapping.values){ // So "Great War Infantry" isn't caught here
@ -463,28 +463,33 @@ class SpecificUnitAutomation{
else UnitAutomation().explore(unit, unit.getDistanceToTiles()) else UnitAutomation().explore(unit, unit.getDistanceToTiles())
} }
fun automateGeneral(unit: MapUnit){ fun automateGreatGeneral(unit: MapUnit){
//try to follow nearby units. Do not garrison in city if possible //try to follow nearby units. Do not garrison in city if possible
val militantToCompany = unit.getDistanceToTiles().map { it.key } val militaryUnitTilesInDistance = unit.getDistanceToTiles().map { it.key }
.firstOrNull {val militant = it.militaryUnit .filter {val militant = it.militaryUnit
militant != null && militant.civInfo == unit.civInfo militant != null && militant.civInfo == unit.civInfo
&& (it.civilianUnit == null || it.civilianUnit == unit) && (it.civilianUnit == null || it.civilianUnit == unit)
&& militant.getMaxMovement() <= 2.0f && !it.isCityCenter()} && militant.getMaxMovement() <= 2 && !it.isCityCenter()}
if(militantToCompany!=null) { if(militaryUnitTilesInDistance.isNotEmpty()) {
unit.movementAlgs().headTowards(militantToCompany) val tilesSortedByAffectedTroops = militaryUnitTilesInDistance
.sortedByDescending { it.getTilesInDistance(2).count {
val militaryUnit = it.militaryUnit
militaryUnit!=null && militaryUnit.civInfo==unit.civInfo
} }
unit.movementAlgs().headTowards(tilesSortedByAffectedTroops.first())
return return
} }
//if no unit to follow, take refuge in city. //if no unit to follow, take refuge in city.
val cityToGarison = unit.civInfo.cities.map {it.getCenterTile()} val cityToGarrison = unit.civInfo.cities.map {it.getCenterTile()}
.filter {it.civilianUnit == null && unit.canMoveTo(it) && unit.movementAlgs().canReach(it)} .sortedBy { it.arialDistanceTo(unit.currentTile) }
.minBy { it.arialDistanceTo(unit.currentTile) } .firstOrNull { it.civilianUnit == null && unit.canMoveTo(it) && unit.movementAlgs().canReach(it)}
if (cityToGarison != null) {
unit.movementAlgs().headTowards(cityToGarison) if (cityToGarrison != null) {
unit.movementAlgs().headTowards(cityToGarrison)
return return
} }
return
} }
fun rankTileAsCityCenter(tileInfo: TileInfo, nearbyTileRankings: Map<TileInfo, Float>): Float { fun rankTileAsCityCenter(tileInfo: TileInfo, nearbyTileRankings: Map<TileInfo, Float>): Float {