Skip to content

Commit

Permalink
sorting by actionCoord if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonBurke committed May 29, 2024
1 parent 52f0c6e commit 901be99
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/room/creeps/creepMoveProcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { CustomPathFinderArgs, PathGoal, CustomPathFinder } from 'international/customPathFinder'
import { packCoord, packPos, packPosList, unpackCoord, unpackPos, unpackPosAt } from 'other/codec'
import {
Utils,
Utils,
areCoordsEqual,
arePositionsEqual,
findAdjacentCoordsToCoord,
Expand Down Expand Up @@ -423,7 +423,6 @@ export class CreepMoveProcs {

const creepInWay = Game.creeps[creepInWayName] || Game.powerCreeps[creepInWayName]
if (creepInWay) {

if (creepInWay.moveRequest === packedCoord) {
potentialCost += 1
}
Expand Down Expand Up @@ -509,7 +508,14 @@ export class CreepMoveProcs {

// Consider sorting by range to action coord, where closer is more preferred
moveOptions.push(...findAdjacentCoordsToCoord(creep.pos))
Utils.shuffleArray(moveOptions)

if (creep.actionCoord) {
moveOptions.sort((a, b) => {
return getRange(a, creep.actionCoord) - getRange(b, creep.actionCoord)
})
} else {
Utils.shuffleArray(moveOptions)
}

creep.moveOptions = moveOptions
return moveOptions
Expand Down

0 comments on commit 901be99

Please sign in to comment.