Last active
February 24, 2017 16:24
-
-
Save ahmaxed/3da17f8b88cf10520942b1c9122032e2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* the original board | |
O | | X | |
--------- | |
X | | X | |
--------- | |
| O | O | |
*/ | |
var origBoard = [“O”,1 ,”X”,”X”,4 ,”X”, 6 ,”O”,”O”]; | |
// human | |
var huPlayer = “O”; | |
// ai | |
var aiPlayer = “X”; | |
// returns list of the indexes of empty spots on the board | |
function emptyIndexies(board){ | |
return board.filter(s => s != "O" && s != "X"); | |
} | |
// winning combinations using the board indexies | |
function winning(board, player){ | |
if ( | |
(board[0] == player && board[1] == player && board[2] == player) || | |
(board[3] == player && board[4] == player && board[5] == player) || | |
(board[6] == player && board[7] == player && board[8] == player) || | |
(board[0] == player && board[3] == player && board[6] == player) || | |
(board[1] == player && board[4] == player && board[7] == player) || | |
(board[2] == player && board[5] == player && board[8] == player) || | |
(board[0] == player && board[4] == player && board[8] == player) || | |
(board[2] == player && board[4] == player && board[6] == player) | |
) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment