diff --git a/dev.js b/dev.js index 7ed7e12..27dc4cd 100644 --- a/dev.js +++ b/dev.js @@ -34,7 +34,7 @@ function showlocalNetAddress(PORT) { networkInterfaces?.['Wi-Fi']?.[1]?.address || networkInterfaces?.Ethernet?.[1]?.address || null; - + if (localNetAddress) { console.log(`network : ${localNetAddress}:${PORT}/`); } else { @@ -42,11 +42,11 @@ function showlocalNetAddress(PORT) { } } -async function start () { +async function start() { try { await app.listen({ port: PORT, host: '::' }); } catch (err) { app.log.error(err); process.exit(1); } -}; +} diff --git a/lib/TicTacToe.js b/lib/TicTacToe.js index 24e98aa..d23eb97 100644 --- a/lib/TicTacToe.js +++ b/lib/TicTacToe.js @@ -21,7 +21,7 @@ function randomInteger(min, max) { } function intSum(min, max) { - return ((max - min) + 1) * (min + max) / 2; + return ((max - min + 1) * (min + max)) / 2; } /** A single thread, blocking, **tic-tac-toe** class game representation that @@ -236,9 +236,10 @@ class TicTacToe { // check diag \ for (let i = 0; i < this.grid; ++i) { - let samePiece = 1, prevPiece = null; + let samePiece = 1, + prevPiece = null; for (let j = 0; j < i + 1; ++j) { - const CURRENT_INDEX = (this.grid - i) + ((this.grid + 1) * j) - 1; + const CURRENT_INDEX = this.grid - i + (this.grid + 1) * j - 1; if (prevPiece === this.board[CURRENT_INDEX] && this.board[CURRENT_INDEX] !== NA) { samePiece++; if (samePiece === this.pieceWinCount) { @@ -253,9 +254,10 @@ class TicTacToe { } for (let i = 1; i < this.grid; ++i) { - let samePiece = 1, prevPiece = null; + let samePiece = 1, + prevPiece = null; for (let j = 0; this.grid - i - j > 0; ++j) { - const CURRENT_INDEX = (i * this.grid) + ((this.grid + 1) * j); + const CURRENT_INDEX = i * this.grid + (this.grid + 1) * j; if (prevPiece === this.board[CURRENT_INDEX] && this.board[CURRENT_INDEX] !== NA) { samePiece++; if (samePiece === this.pieceWinCount) { @@ -271,9 +273,10 @@ class TicTacToe { // check diag / for (let i = 0; i < this.grid; ++i) { - let samePiece = 1, prevPiece = null; + let samePiece = 1, + prevPiece = null; for (let j = 0; j < i + 1; ++j) { - const CURRENT_INDEX = i + (j * this.grid) - j; + const CURRENT_INDEX = i + j * this.grid - j; if (prevPiece === this.board[CURRENT_INDEX] && this.board[CURRENT_INDEX] !== NA) { samePiece++; if (samePiece === this.pieceWinCount) { @@ -288,9 +291,10 @@ class TicTacToe { } for (let i = 1; i < this.grid; ++i) { - let samePiece = 1, prevPiece = null; + let samePiece = 1, + prevPiece = null; for (let j = 0; this.grid - i - j > 0; ++j) { - const CURRENT_INDEX = ((this.grid * (i + 1)) - 1) + ((this.grid - 1) * j); + const CURRENT_INDEX = this.grid * (i + 1) - 1 + (this.grid - 1) * j; if (prevPiece === this.board[CURRENT_INDEX] && this.board[CURRENT_INDEX] !== NA) { samePiece++; if (samePiece === this.pieceWinCount) { diff --git a/lib/script.js b/lib/script.js index a31017e..4b15e66 100644 --- a/lib/script.js +++ b/lib/script.js @@ -79,9 +79,9 @@ SELECT_GRID.addEventListener('change', () => { setNewGame( 'The depth has been optimized in relation to the grid value to ' + - 'improve the calculation speed. You can adjust the depth value, ' + - 'but keep in mind that higher values for "depth and grid" will ' + - 'will take more time to calculate or might even crash the page.' + 'improve the calculation speed. You can adjust the depth value, ' + + 'but keep in mind that higher values for "depth and grid" will ' + + 'will take more time to calculate or might even crash the page.' ); }); @@ -127,7 +127,7 @@ function generateCells() { for (let j = 0; j < Game.grid; ++j) { const square = document.createElement('span'); square.className = 'cell'; - square.style.animationDelay = `${(i * 0.1) + (j * 0.1) + 0.1}s`; + square.style.animationDelay = `${i * 0.1 + j * 0.1 + 0.1}s`; square.addEventListener('click', () => makeMove(i, j)); diff --git a/readme.md b/readme.md index 7162b56..50f11db 100644 --- a/readme.md +++ b/readme.md @@ -24,4 +24,3 @@ node dev ``` Then open `localhost:3000` in your browser. - diff --git a/tests.js b/tests.js index 1e8cdc1..6afe777 100644 --- a/tests.js +++ b/tests.js @@ -6,53 +6,15 @@ let failedTests = 0; const fbfWinners = [NA, P1, P2, P1, P2, P1, P2, P1, P2]; const fbfBoardStates = [ - [ - P2, NA, NA, P2, - NA, P1, NA, NA, - NA, NA, P2, NA, - P1, NA, NA, P1 - ], - [ - NA, NA, P1, NA, - NA, P1, NA, NA, - P1, NA, NA, NA, - NA, NA, NA, NA - ],[ - NA, NA, NA, NA, - NA, NA, NA, P2, - NA, NA, P2, NA, - NA, P2, NA, NA - ],[ - NA, P1, NA, NA, - NA, NA, P1, NA, - NA, NA, NA, P1, - NA, NA, NA, NA - ],[ - NA, NA, NA, NA, - P2, NA, NA, NA, - NA, P2, NA, NA, - NA, NA, P2, NA - ],[ - NA, NA, NA, NA, - NA, NA, P1, NA, - NA, P1, NA, NA, - P1, NA, NA, NA - ],[ - NA, NA, NA, NA, - NA, P2, NA, NA, - NA, NA, P2, NA, - NA, NA, NA, P2 - ],[ - NA, NA, NA, P1, - NA, NA, P1, NA, - NA, P1, NA, NA, - NA, NA, NA, NA - ],[ - P2, NA, NA, NA, - NA, P2, NA, NA, - NA, NA, P2, NA, - NA, NA, NA, NA - ], + [P2, NA, NA, P2, NA, P1, NA, NA, NA, NA, P2, NA, P1, NA, NA, P1], + [NA, NA, P1, NA, NA, P1, NA, NA, P1, NA, NA, NA, NA, NA, NA, NA], + [NA, NA, NA, NA, NA, NA, NA, P2, NA, NA, P2, NA, NA, P2, NA, NA], + [NA, P1, NA, NA, NA, NA, P1, NA, NA, NA, NA, P1, NA, NA, NA, NA], + [NA, NA, NA, NA, P2, NA, NA, NA, NA, P2, NA, NA, NA, NA, P2, NA], + [NA, NA, NA, NA, NA, NA, P1, NA, NA, P1, NA, NA, P1, NA, NA, NA], + [NA, NA, NA, NA, NA, P2, NA, NA, NA, NA, P2, NA, NA, NA, NA, P2], + [NA, NA, NA, P1, NA, NA, P1, NA, NA, P1, NA, NA, NA, NA, NA, NA], + [P2, NA, NA, NA, NA, P2, NA, NA, NA, NA, P2, NA, NA, NA, NA, NA], ]; console.log('============ 4x4 - piece 3 win state tests ============ ');