mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-06-28 12:55:36 -04:00
feat: added game evaluation
This commit is contained in:
parent
75b99514de
commit
8a97cde4fa
1 changed files with 74 additions and 75 deletions
|
@ -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(){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue