Skip to content

Instantly share code, notes, and snippets.

@varyform
Created January 15, 2021 17:26
Show Gist options
  • 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 })
@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