Created
November 19, 2011 18:16
-
-
Save adomokos/1379158 to your computer and use it in GitHub Desktop.
The TicTacToe game's ScoreBoard class is taking shape
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
class App.ScoreBoard | |
permutations = | |
[['A_1', 'B_1', 'C_1'], | |
['A_2', 'B_2', 'C_2'], | |
['A_3', 'B_3', 'C_3'], | |
['A_1', 'A_2', 'A_3'], | |
['B_1', 'B_2', 'B_3'], | |
['C_1', 'C_2', 'C_3'], | |
['A_1', 'B_2', 'C_3'], | |
['A_3', 'B_2', 'C_1']] | |
result: (gameBoard) -> | |
check_for_winners = (x_or_o) -> | |
for permutation in permutations | |
if(gameBoard.moves[permutation[0]] == x_or_o and | |
gameBoard.moves[permutation[1]] == x_or_o and | |
gameBoard.moves[permutation[2]] == x_or_o) | |
return true | |
return false | |
result = check_for_winners('x') | |
return App.X_WINS if result | |
result = check_for_winners('o') | |
return App.O_WINS if result | |
return App.UNDECIDED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wish I {enumberable}.all? would be available in CoffeeScript. I don't like line 17-19.