Last active
August 29, 2015 14:26
-
-
Save powersjcb/6fa94b85deb053eacd11 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
# 1. Create a Hash with keys of directions that have been checked for a match | |
class Piece | |
@checked_directions = {:horizontal => false, :vertical => false, :left_diag => false, :right_diag => false} | |
end | |
# 2. Iterate through each element (as was previously implemented) | |
# DUP All the pieces for this next step O(n^2) where n is the width of the grid. | |
dup_pieces = pieces.map {|el| el.dup} | |
pieces.any? { |piece| piece.winning? } | |
# 3. Winning will now only iterate through directions that have not been checked yet, | |
# it will need to extend in both directions. If it finds it not to be winning, return false. | |
def winning? | |
@checked_directions.each do |dir, checked_yet| | |
when dir | |
case :horizontal | |
if !checked_yet # will only run if the row has not already been checked | |
# left_sum = iterate through all contiguous Peices to the left until end case | |
# right_sum = iterate through all contiguous Peices to the right until end case | |
### at each piece you check, mark as checked ### | |
else | |
# DONT CHECK ANYTHING IN THIS ROW ANYMORE | |
end | |
case : | |
... | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment