Skip to content

Instantly share code, notes, and snippets.

@varyform
Created January 15, 2021 17:26
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 varyform/364d537a61b4e6645cc1c05342a927bf to your computer and use it in GitHub Desktop.
Save varyform/364d537a61b4e6645cc1c05342a927bf to your computer and use it in GitHub Desktop.
wins = [
# rows
0b000000111,
0b000111000,
0b111000000,
# cols
0b100100100,
0b010010010,
0b001001001,
# diags
0b100010001,
0b001010100
]
board = 0b101010111
puts(wins.any? { |w| w & board == w })
@apauly
Copy link

apauly commented Jan 15, 2021

Nice idea!
But it lacks one crucial feature, which is to tell if a cell has been filled or not ;)

- O -
O - O
X X X

If nil would equal 0, the wrong person would have won in this case ;)

@varyform
Copy link
Author

Oh... it's not my idea :)
It's a check from player's perspective.
So there is no need for "empty cell" state.

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