Skip to content

Commit

Permalink
[Auto-format code on push]
Browse files Browse the repository at this point in the history
Formatted the last commit -> 'auto code format on push'
  • Loading branch information
mrdcvlsc committed Jun 30, 2023
1 parent c5b5817 commit 43d356b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 108 deletions.
26 changes: 4 additions & 22 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,20 @@
import path from 'path';
import {





fileURLToPath } from 'url';
import { fileURLToPath } from 'url';
import { showLocalNetworkIP } from './shownet.js';

const __filename =
fileURLToPath(
import.meta.url



);
const __filename = fileURLToPath(import.meta.url);


const __dirname = path.
dirname(__filename);
const __dirname = path.dirname(__filename);

const PORT = process.env.PORT || 8080;
showLocalNetworkIP(
PORT);
showLocalNetworkIP(PORT);

import fastify from 'fastify';

const app = fastify({
logger: false,
});




import fastifyStatic from '@fastify/static';

app.register(fastifyStatic.default, {
Expand Down
47 changes: 7 additions & 40 deletions public/TicTacToe.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,30 @@
'use strict';
console.log('TicTacToe.js: loaded.'





);
console.log('TicTacToe.js: loaded.');

/** Empty square value, Not Available ` `. */
const NA = 0;
const NOWINNER =













0;
const NOWINNER = 0;

/** Player 1 square value `X`. */
const P1 = 1;

/** Player 2 square value `O`. */
const P2 = 2;
const CELL_PIECE = ['',
'X', 'O'

];
const CELL_PIECE = ['', 'X', 'O'];

const MOVE_SUCCESS = 1;

const MOVE_INVALID =
0;
const MOVE_INVALID = 0;

/** A single thread tic-tac-toe game representation that can uses
* `minimax` algorithm to search for the best possible move.
*/
class TicTacToe {
constructor(gridLength, player = P1){this.grid = gridLength;
constructor(gridLength, player = P1) {
this.grid = gridLength;
this.winner = 0;

this.board = new Uint8Array(



gridLength * gridLength





);
this.board = new Uint8Array(gridLength * gridLength);
this.currentPlayer = P1;
this.turns = gridLength * gridLength;

Expand Down
46 changes: 11 additions & 35 deletions public/script.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,26 @@
// =================== tic-tac-toe minimax ===================
import { TicTacToe











} from './TicTacToe.js';
import { TicTacToe } from './TicTacToe.js';

let game = new TicTacToe(3);

const PIECE = [' ', '✕', '◯'];
const PIECE = [' ', '✕', '◯'];

const SUCCESS =
1;
const SUCCESS = 1;
const INVALID = 0;

function announceResult(flag) {









console.log(flag);



if (game.winner === 0) {
htmlMessage.innerText = 'Game ended in a draw.';
htmlMessage.style.color = 'yellow';
htmlMessage.style.fontSize = '1.15em';
htmlMessage.style.fontWeight = 'bolder';
htmlMessage.innerText = 'Game ended in a draw.';
htmlMessage.style.color = 'yellow';
htmlMessage.style.fontSize = '1.15em';
htmlMessage.style.fontWeight = 'bolder';
} else {
htmlMessage.innerHTML = `Player ${PIECE[game.winner]} won.`;
htmlMessage.style.color = 'lightgreen';
htmlMessage.style.fontSize = '1.15em';
htmlMessage.style.fontWeight = 'bolder';
htmlMessage.innerHTML = `Player ${PIECE[game.winner]} won.`;
htmlMessage.style.color = 'lightgreen';
htmlMessage.style.fontSize = '1.15em';
htmlMessage.style.fontWeight = 'bolder';
}
}

Expand Down
2 changes: 0 additions & 2 deletions shownet.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ function showLocalNetworkIP(PORT) {
}
}



export { showLocalNetworkIP };
10 changes: 1 addition & 9 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ import { TicTacToe, NA, P1, P2 } from './public/TicTacToe.js';
const t = new TicTacToe(3);
let failedTests = 0;

const winners = [NA,
P1,
P1,
P1,

P1, P1, P1, P2, P2, P2, P2, P2, P2, P1, P1, P2, P2];



const winners = [NA, P1, P1, P1, P1, P1, P1, P2, P2, P2, P2, P2, P2, P1, P1, P2, P2];

const winBoardStates = [
[NA, NA, NA, NA, NA, NA, NA, NA, NA],
Expand Down

0 comments on commit 43d356b

Please sign in to comment.