Skip to content

Commit

Permalink
refactor(TicTacToe.js): new initialization method.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The TicTacToe.js will now use an options object when initialized instead of multiple function parameters.
  • Loading branch information
mrdcvlsc committed Jun 30, 2023
1 parent 9efbe6c commit b9890ff
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions public/TicTacToe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b9890ff

Please sign in to comment.