const board = [];
let player = "X";
for (let i = 0; i < 3; i++) {
board.push([" ", " ", " "]);
}
const printBoard = () => {
console.log(` ${board[0][0]} | ${board[0][1]} | ${board[0][2]} `);
console.log("---+---+---");
console.log(` ${board[1][0]} | ${board[1][1]} | ${board[1][2]} `);
console.log("---+---+---");
console.log(` ${board[2][0]} | ${board[2][1]} | ${board[2][2]} `);
};
const makeMove = (row, col) => {
board[row][col] = player;
player = player === "X" ? "O" : "X";
};
const isWin = () => {
for (let i = 0; i < 3; i++) {
if (board[i][0] === board[i][1] && board[i][1] === board[i][2] && board[i][0] !== " ") {
return true;
}
if (board[0][i] === board[1][i] && board[1][i] === board[2][i] && board[0][i] !== " ") {
return true;
}
}
if (board[0][0] === board[1][1] && board[1][1] === board[2][2] && board[0][0] !== " ") {
return true;
}
if (board[0][2] === board[1][1] && board[1][1] === board[2][0] && board[0][2] !== " ") {
return true;
}
return false;
};
printBoard();
makeMove(0, 0);
printBoard();
makeMove(1, 1);
printBoard();
makeMove(2, 2);
printBoard();
console.log(isWin());
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});