paint AI win as well
authorDylan Lloyd <dylan@dylansserver.com>
Tue, 16 Jun 2015 20:31:24 +0000 (13:31 -0700)
committerDylan Lloyd <dylan@dylansserver.com>
Tue, 16 Jun 2015 20:31:24 +0000 (13:31 -0700)
ai.js

diff --git a/ai.js b/ai.js
index c3046de..4908f52 100644 (file)
--- 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;