diff --git a/common/src/algorithms/movementDirection.ts b/common/src/algorithms/movementDirection.ts index 29f34ae..9348a82 100644 --- a/common/src/algorithms/movementDirection.ts +++ b/common/src/algorithms/movementDirection.ts @@ -40,8 +40,27 @@ export function countShips(board: any[], shipLocation: number) { * - `1` = Towards the Warp Gate */ export function determineDirection(board: any[], shipLocation: number) { - let delta = 1; + /* + Edge-Case check for when the board only has a single ship on it because any + ships that hit the warp gate get removed from the game, and ships in the + singularity don't create gravity wells, not affecting other ships. + */ + let shipCount = 0; + for (const location of board) { + if (location != null) { + shipCount++; + if (shipCount >= 2) { + break; + }; + }; + }; + if (shipCount == 1) { + return 1; + }; + + + let delta = 1; while (true) { // The left side of the board is out of range, nearest ship is always // right