Improved AI city location picking

Done by ignoring tiles already belonging to another civ / within work range of another city
This commit is contained in:
Yair Morgenstern 2023-06-12 10:27:21 +03:00
parent 404a148cfb
commit e5232494a0
2 changed files with 16 additions and 18 deletions

View File

@ -42,10 +42,7 @@ object CityLocationTileRanker {
val distanceFromHome = if (unit.civ.cities.isEmpty()) 0 val distanceFromHome = if (unit.civ.cities.isEmpty()) 0
else unit.civ.cities.minOf { it.getCenterTile().aerialDistanceTo(unit.getTile()) } else unit.civ.cities.minOf { it.getCenterTile().aerialDistanceTo(unit.getTile()) }
val range = (8 - distanceFromHome).coerceIn( val range = (8 - distanceFromHome).coerceIn(1, 5) // Restrict vision when far from home to avoid death marches
1,
5
) // Restrict vision when far from home to avoid death marches
val possibleCityLocations = unit.getTile().getTilesInDistance(range) val possibleCityLocations = unit.getTile().getTilesInDistance(range)
.filter { canUseTileForRanking(it, unit.civ) } .filter { canUseTileForRanking(it, unit.civ) }
@ -60,15 +57,14 @@ object CityLocationTileRanker {
return possibleCityLocations return possibleCityLocations
.map { .map {
Pair( it to
it,
rankTileAsCityCenterWithCachedValues( rankTileAsCityCenterWithCachedValues(
it, it,
nearbyTileRankings, nearbyTileRankings,
luxuryResourcesInCivArea, luxuryResourcesInCivArea,
unit.civ unit.civ
),
) )
} }
.sortedByDescending { it.second } .sortedByDescending { it.second }
} }
@ -88,8 +84,10 @@ object CityLocationTileRanker {
tile: Tile, tile: Tile,
civ: Civilization civ: Civilization
) = ) =
// The AI is allowed to cheat and act like it knows the whole map.
tile.isExplored(civ) || civ.isAI() (tile.isExplored(civ) || civ.isAI()) // The AI is allowed to cheat and act like it knows the whole map.
&& (tile.getOwner() == null ||
tile.getOwner() == civ && tile.getTilesInDistance(3).none { it.isCityCenter() })
private fun getNearbyTileRankings( private fun getNearbyTileRankings(
tile: Tile, tile: Tile,

View File

@ -127,9 +127,9 @@ These shapes are used all over Unciv and can be replaced to make a lot of UI ele
| WorldScreen/TopBar/ | ResourceTable | null | | | WorldScreen/TopBar/ | ResourceTable | null | |
| WorldScreen/TopBar/ | RightAttachment | roundedEdgeRectangle | | | WorldScreen/TopBar/ | RightAttachment | roundedEdgeRectangle | |
| WorldScreen/TopBar/ | StatsTable | null | | | WorldScreen/TopBar/ | StatsTable | null | |
| WorldScreenMusicPopup/TrackList/ | Down", tintColor = skin.getColor("positive | null | | | WorldScreenMusicPopup/TrackList/ | Down | null | |
| WorldScreenMusicPopup/TrackList/ | Over", tintColor = skin.getColor("highlight | null | | | WorldScreenMusicPopup/TrackList/ | Over | null | |
| WorldScreenMusicPopup/TrackList/ | Up", tintColor = skin.getColor("color | null | | | WorldScreenMusicPopup/TrackList/ | Up | null | |
<!--- DO NOT REMOVE OR MODIFY THIS LINE UI_ELEMENT_TABLE_REGION_END --> <!--- DO NOT REMOVE OR MODIFY THIS LINE UI_ELEMENT_TABLE_REGION_END -->
## SkinConfig ## SkinConfig