Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
The TicTacToe game's ScoreBoard class is taking shape
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
Copy link

adomokos commented Nov 19, 2011

I wish I {enumberable}.all? would be available in CoffeeScript. I don't like line 17-19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment