mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-22 04:29:17 +07:00
Added BFS for arial movement
This commit is contained in:
parent
367e1d8517
commit
7bbd006180
@ -21,8 +21,8 @@ android {
|
||||
applicationId "com.unciv.app"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 28
|
||||
versionCode 271
|
||||
versionName "2.18.0"
|
||||
versionCode 272
|
||||
versionName "2.18.1"
|
||||
}
|
||||
|
||||
// Had to add this crap for Travis to build, it wanted to sign the app
|
||||
|
@ -310,4 +310,29 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
||||
}
|
||||
|
||||
fun getDistanceToTiles() = getDistanceToTilesWithinTurn(unit.currentTile.position,unit.currentMovement)
|
||||
|
||||
fun getArialMovementBfsTree(startingTile: TileInfo): HashMap<TileInfo, TileInfo> {
|
||||
var tilesToCheck = ArrayList<TileInfo>()
|
||||
/** each tile reached points to its parent tile, where we got to it from */
|
||||
val tilesReached = HashMap<TileInfo, TileInfo>()
|
||||
|
||||
tilesToCheck.add(startingTile)
|
||||
tilesReached[startingTile] = startingTile
|
||||
|
||||
|
||||
while(tilesToCheck.isNotEmpty()) {
|
||||
val newTilesToCheck = ArrayList<TileInfo>()
|
||||
for(tileToCheck in tilesToCheck){
|
||||
val reachableTiles = tileToCheck.getTilesInDistance(unit.getRange())
|
||||
.filter { unit.movement.canMoveTo(it) }
|
||||
for(reachableTile in reachableTiles){
|
||||
if(tilesReached.containsKey(reachableTile)) continue
|
||||
tilesReached[reachableTile]=tileToCheck
|
||||
newTilesToCheck.add(reachableTile)
|
||||
}
|
||||
}
|
||||
tilesToCheck=newTilesToCheck
|
||||
}
|
||||
return tilesReached
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user