Created
July 27, 2019 19:05
-
-
Save rugyoga/9425bee8ee5e387d3bbfbd39004a3505 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
def northwest(file, rank) | |
file + rank | |
end | |
def northeast(file, rank) | |
file + @size - rank | |
end | |
def unsafe?(file, rank) | |
@queens.any? do |f, r| | |
r == rank || | |
northwest(f, r) == northwest(file, rank) || | |
northeast(f, r) == northeast(file, rank) | |
end | |
end | |
def move!(file, rank) | |
@queens.push([file, rank]) | |
end | |
def unmove!(_file, _rank) | |
@queens.pop | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment