Apply a fix to the determineDirection function that makes it conform to the rule specification
This commit is contained in:
parent
3b78f224df
commit
670729c892
1 changed files with 20 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue