rm comments
authorDylan Lloyd <dylan@dylansserver.com>
Tue, 16 Jun 2015 02:52:01 +0000 (19:52 -0700)
committerDylan Lloyd <dylan@dylansserver.com>
Tue, 16 Jun 2015 02:52:01 +0000 (19:52 -0700)
ai.js

diff --git a/ai.js b/ai.js
index 90779ae..ec725b4 100644 (file)
--- a/ai.js
+++ b/ai.js
@@ -86,14 +86,12 @@ $(document).ready(function(){
                 var cell = tictactoe.cells[i][ii];
                 if (x > cell.x && x < cell.x + cell.size
                     && y > cell.y && y < cell.y + cell.size) {
-                    //cell.play(Math.random() > 0.5 ? 'x' : 'o');
                     if (!cell.state) {
                         var player = 'x';
                         cell.play(player);
                         if (!endCondition(tictactoe.serialize())) {
                             var aiMove = minimax(tictactoe.serialize(),
                                 player == 'o' ? 'x' : 'o').move;
-                            //console.log(aiMove);
                             tictactoe.cells[aiMove[1]][aiMove[0]].play(player == 'o' ? 'x' : 'o');
                         }
                         return;
@@ -108,11 +106,8 @@ $(document).ready(function(){
         for (var i = 0; i < state.length; i++) {
             for (var ii = 0; ii < state[i].length; ii++) {
                 if (!state[i][ii]) {
-                    //console.log(state[i][ii]);
-                    //console.log('i: ' + i + ', ii: ' + ii);
                     var future = jQuery.extend(true, [], state);
                     future[i][ii] = player;
-                    //possibilities.push(future);
                     possibilities.push({
                         'state'  : future,
                         'x'      : ii,
@@ -125,7 +120,6 @@ $(document).ready(function(){
     }
 
     function endCondition(state) {
-        //console.log('checking for end condition');
         var horizontalPlayer, horizontalTally = 0;
         var verticalPlayer, verticalTally = 0;
         var diagonalPlayer, diagonalTally = 0;
@@ -187,7 +181,6 @@ $(document).ready(function(){
         if (!eog && fullCells == size*size)
             eog = 'tie';
 
-        //console.log('endCondition: ' + eog);
         return eog ? eog : false;
     }
 
@@ -196,33 +189,27 @@ $(document).ready(function(){
         if (result && result !== 'tie')
             return result == player ? 1 : -1;
         if (result == 'tie') {
-            //console.log(state + ' is a tie');
             return 0;
         }
         return false;
     }
 
     function minimax(state, player, activePlayer) {
-        //console.log('minimax: ' + state + ' for ' + player);
         var activePlayer = typeof activePlayer == 'undefined' ? (player == 'x' ? 'o' : 'x') : activePlayer;
         var nextPlayer = activePlayer == 'x' ? 'o' : 'x';
         var win = score(state, activePlayer);
-        //console.log('got score: ' + win);
         if (win !== false) {
             if (win == 'tie')
                 win = 0;
             if (player != activePlayer && win !== 0)
                 win = win === 1 ? -1 : 1;
-            //console.log('found ' + (win === 1 ? 'win' : 'loss') + ' for ' + activePlayer + ' returning ' + win);
             return win;
         }
         var scores = [];
-        //console.log('generating futures for ' + player);
         var futures = generate(state, nextPlayer);
         for (var i in futures) {
             var future = futures[i];
             var result = minimax(future.state, player, nextPlayer);
-            //console.log('got result: ' + result);
             if (typeof result == 'object')
                 result = result.score;
             scores.push({
@@ -231,8 +218,6 @@ $(document).ready(function(){
             });
         }
         if (activePlayer == player) {
-            //console.log('finding minimum score for ' + activePlayer + ' at ' + state);
-            //console.log(scores);
             var bestScore = 1;
             var bestMove;
             for (var i in scores) {
@@ -241,14 +226,11 @@ $(document).ready(function(){
                     bestMove = scores[i].move;
                 }
             }
-            //console.log('chose ' + bestMove + ' with score  ' + bestScore);
             return {
                 'move'  : bestMove,
                 'score' : bestScore
             };
         } else {
-            //console.log('finding maximum score for ' + activePlayer + ' at ' + state);
-            //console.log(scores);
             var bestScore = -1;
             var bestMove;
             for (var i in scores) {
@@ -257,30 +239,13 @@ $(document).ready(function(){
                     bestMove = scores[i].move;
                 }
             }
-            //console.log('chose ' + bestMove + ' with score ' + bestScore);
             return {
                 'move'  : bestMove,
                 'score' : bestScore
             };
         }
-        //console.log('should never ever get here, activePlayer is ' + activePlayer + ' player is: ' + player);
     }
 
     var tictactoe = new board(3, 'player').init();
 
-//    tictactoe.cells[0][0].play('o');
-//    tictactoe.cells[0][2].play('x');
-//    tictactoe.cells[1][0].play('x');
-//    tictactoe.cells[2][0].play('x');
-//    tictactoe.cells[2][1].play('o');
-
-
-//    tictactoe.cells[1][0].play('x');
-//    tictactoe.cells[0][2].play('o');
-//    tictactoe.cells[1][1].play('x');
-//    tictactoe.cells[2][1].play('o');
-//
-//    tictactoe.cells[2][2].play('x');
-//    tictactoe.cells[1][2].play('o');
-
 });