From: Dylan Lloyd Date: Tue, 16 Jun 2015 20:31:24 +0000 (-0700) Subject: paint AI win as well X-Git-Url: https://disinclined.org/git/?a=commitdiff_plain;h=73b95e9a533081d53bbe53df57e4fe1cb989162f;p=minimax.git paint AI win as well --- diff --git a/ai.js b/ai.js index c3046de..4908f52 100644 --- a/ai.js +++ b/ai.js @@ -91,11 +91,11 @@ $(document).ready(function(){ if (!cell.state) { var player = 'x'; cell.play(player); - if (!endCondition(tictactoe.serialize(), 'paintWin')) { - console.log('play ball'); + if (!endCondition(tictactoe.serialize(), true)) { var aiMove = minimax(tictactoe.serialize(), player == 'o' ? 'x' : 'o').move; - //tictactoe.cells[aiMove[1]][aiMove[0]].play(player == 'o' ? 'x' : 'o'); + tictactoe.cells[aiMove[1]][aiMove[0]].play(player == 'o' ? 'x' : 'o'); + endCondition(tictactoe.serialize(), true); } return; } @@ -123,7 +123,6 @@ $(document).ready(function(){ } function endCondition(state, paint) { - console.log('endcondition'); var horizontalPlayer, horizontalTally = 0; var verticalPlayer, verticalTally = 0; var diagonalPlayer, diagonalTally = 0; @@ -191,9 +190,8 @@ $(document).ready(function(){ if (paint) for (var i = 0; i < size; i++) tictactoe.cells[i][(size-1)-i].play(eog, 'green'); - break; + return antiDiagonalPlayer; } - console.log('still looping :-('); } } return eog ? eog : false;