Created
January 15, 2021 17:26
-
-
Save varyform/364d537a61b4e6645cc1c05342a927bf to your computer and use it in GitHub Desktop.
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
wins = [ | |
# rows | |
0b000000111, | |
0b000111000, | |
0b111000000, | |
# cols | |
0b100100100, | |
0b010010010, | |
0b001001001, | |
# diags | |
0b100010001, | |
0b001010100 | |
] | |
board = 0b101010111 | |
puts(wins.any? { |w| w & board == w }) |
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
Nice idea!
But it lacks one crucial feature, which is to tell if a cell has been filled or not ;)
If
nil
would equal0
, the wrong person would have won in this case ;)