-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AI Code and Drawing functions now working
Added the code for the AI and the functions that draw the X and 0 on the grid.
- Loading branch information
1 parent
d509ef6
commit 23be6ca
Showing
4 changed files
with
46 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
var SCORES = { | ||
2: 1, | ||
4: 0, | ||
3: -1 | ||
}; | ||
|
||
var app = angular.module("TicTacToe", []); | ||
|
||
app.controller("TTTController", ['$scope', function($scope){ | ||
var ticTacGUI = new TTTGUI(3, PLAYERO, move_wrapper, 1, false); | ||
var board = new TTTBoard(3); | ||
}]); | ||
|
||
function move_wrapper(){ | ||
return null; | ||
function mm_move(board, player){ | ||
var scores = [[], []], moves = [], board_copy, winner, | ||
empty_squares = board.get_empty_squares(); | ||
//console.log(board.get_empty_squares()); | ||
for (var i = 0; i < empty_squares.length; i++){ | ||
board_copy = board.clone(); | ||
board_copy.move(empty_squares[i][0], empty_squares[i][1], player); | ||
winner = board_copy.check_win(); | ||
if (winner != null){ | ||
scores[0].push(SCORES[winner]); | ||
scores[1].push(empty_squares[i]); | ||
} else { | ||
next_move = mm_move(board_copy, switch_player(player)); | ||
scores[0].push(next_move[0]); | ||
scores[1].push(empty_squares[i]); | ||
} | ||
} | ||
if (player == PLAYERX) { | ||
minimax = [Math.max(...scores[0]), scores[1][scores[0].indexOf(Math.max(...scores[0]))]]; | ||
} else { | ||
minimax = [Math.min(...scores[0]), scores[1][scores[0].indexOf(Math.min(...scores[0]))]]; | ||
} | ||
|
||
return minimax; | ||
//return [2, [0, 1]]; | ||
} | ||
|
||
function move_wrapper(board, player, trials){ | ||
var move = mm_move(board, player); | ||
return move[1]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters