Skip to content

Instantly share code, notes, and snippets.

@adomokos
Created November 19, 2011 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adomokos/1379158 to your computer and use it in GitHub Desktop.
Save adomokos/1379158 to your computer and use it in GitHub Desktop.
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
@adomokos
Copy link
Author

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