diff --git a/public/TicTacToe.js b/public/TicTacToe.js index a96e4e7..04f3c43 100644 --- a/public/TicTacToe.js +++ b/public/TicTacToe.js @@ -20,8 +20,18 @@ const MOVE_INVALID = 0; * `minimax` algorithm to search for the best possible move. */ class TicTacToe { - constructor(gridLength, player = P1) { - this.grid = gridLength; + constructor(options = {gridLength, winCount, player}) { + this.grid = (options?.gridLength) ? options.gridLength : 3; + + let pieceWinCount = (options?.winCount) ? options.winCount : 3; + + if (pieceWinCount > this.grid) { + pieceWinCount = this.grid; + } + + this.pieceWinCount = pieceWinCount; + this.player = (options?.player) ? (options.player === P1 || options.player === P2) ? options.player : P1 : P1; + this.winner = 0; this.board = new Uint8Array(gridLength * gridLength);