feat: added game evaluation

This commit is contained in:
Smigz 2023-12-13 17:17:20 -05:00
parent 75b99514de
commit 8a97cde4fa

View file

@ -120,10 +120,6 @@ function block() {
}; };
}; };
const gameController = (() => { const gameController = (() => {
// Controls the overall flow of the game // Controls the overall flow of the game
let players = [ let players = [
@ -147,7 +143,10 @@ const gameController = (() => {
marker.addToken(player); marker.addToken(player);
tictactoeBoard.placeOnBoard(position, marker); // position on board tictactoeBoard.placeOnBoard(position, marker); // position on board
tictactoeBoard.printGameBoard(); tictactoeBoard.printGameBoard();
let gameOver = evalGameOutcome(tictactoeBoard);
if (!gameOver) {
switchPlayerTurn(); switchPlayerTurn();
}
} else { } else {
return return
} }
@ -168,7 +167,9 @@ const gameController = (() => {
let checkGameBoard = [gameBoard, diagArray, vertArray]; let checkGameBoard = [gameBoard, diagArray, vertArray];
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
let outcome = _evalGameOutcome(checkGameBoard[i]); let outcome = _evalGameOutcome(checkGameBoard[i]);
if (outcome) return outcome[0]; if (outcome) {
return true;
};
}; };
return false; return false;
}; };
@ -196,8 +197,6 @@ gameController.playRound(4);
gameController.playRound(4); gameController.playRound(4);
gameController.playRound(5); gameController.playRound(5);
// tictactoeBoard.placeOnBoard(1, block)
// tictactoeBoard.printGameBoard();
// const inputController = (function(){ // const inputController = (function(){