Created
November 24, 2014 17:33
-
-
Save JackBracken/29c446c7345bda0aad6f 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 game_over? | |
count = 0 | |
token = last_token = "" | |
@board.each_index do |col| | |
# Look ahead then track back in each column | |
0.upto(2) do |y| | |
# If the space we are looking at is empty then skip it | |
next if @board[col][y].eql?(EMPTY_SPACE) | |
next unless @board[col][y].eql?(@board[col][y + 3]) | |
next unless @board[col][y].eql?(@board[col][y + 2]) | |
return true if @board[col][y].eql?(@board[col][y + 1]) | |
end | |
@board[col].each_index do |row| | |
# Look ahead then track back in each row | |
0.upto(3) do |x| | |
# If the space we are looking at is empty then skip it | |
next if @board[x][row].eql?(EMPTY_SPACE) | |
next unless @board[x][row].eql?(@board[x + 3][row]) | |
next unless @board[x][row].eql?(@board[x + 2][row]) | |
return true if @board[x][row].eql?(@board[x + 1][row]) | |
end | |
end | |
end | |
false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment