Compare commits

..

No commits in common. "8020d30d6b43f0680a40265a31a9a3d766280602" and "9107c557afa3fbf98d2be164b801b3653456a2b3" have entirely different histories.

View file

@ -8,11 +8,6 @@ import { State } from "./State.js";
*/ */
export class Game export class Game
{ {
/**
* The number of chips required for a win.
*/
static #count = 4;
/** /**
* The width of the board. * The width of the board.
*/ */
@ -79,50 +74,6 @@ export class Game
return this.state.board; return this.state.board;
} }
/**
* Gets the id of the player that is winning.
*
* @type {CellOwner}
*/
get winner()
{
for (let yOffset = 0; yOffset <= 1; yOffset++)
{
for (let xOffset = (yOffset === 1) ? -1 : 1; xOffset <= 1; xOffset++)
{
let lowerBound = Math.max(0, xOffset * (Game.#count - 1) * -1);
let upperBound = Math.min(Game.#width, Game.#width - (xOffset * (Game.#count - 1)));
for (let y = 0; y < (Game.#height - yOffset * (Game.#count - 1)); y++)
{
for (let x = lowerBound; x < upperBound; x++)
{
/**
* @type {CellOwner[]}
*/
let tokens = [];
for (let i = 0; i < Game.#count; i++)
{
tokens.push(this.board[y + i * yOffset][x + i * xOffset]);
}
let player = tokens[0];
if (
player !== "" &&
tokens.every((token) => token === player))
{
return player;
}
}
}
}
}
return null;
}
/** /**
* Dumps the state of the game. * Dumps the state of the game.
* *
@ -238,8 +189,6 @@ export class Game
{ {
className: this.state.currentPlayer className: this.state.currentPlayer
}, },
this.winner ?
`Player ${Constants.PLAYER_NAMES[this.winner]} wins!` :
`It's player "${Constants.PLAYER_NAMES[this.state.currentPlayer]}"s turn` `It's player "${Constants.PLAYER_NAMES[this.state.currentPlayer]}"s turn`
], ],
this.#log); this.#log);
@ -258,8 +207,6 @@ export class Game
* A value indicating whether the chip could be added. * A value indicating whether the chip could be added.
*/ */
addChip(x, y) addChip(x, y)
{
if (!this.winner)
{ {
for (let i = Game.#height - 1; i >= 0; i--) for (let i = Game.#height - 1; i >= 0; i--)
{ {
@ -269,7 +216,6 @@ export class Game
return true; return true;
} }
} }
}
return false; return false;
} }