Created
March 2, 2014 19:11
-
-
Save dastels/9311961 to your computer and use it in GitHub Desktop.
Boggle search
This file contains hidden or 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 start | |
| (0...15).each do |start_position| | |
| return true if search(@query, | |
| integer_to_yx(start_position), | |
| [integer_to_yx(start_position)]) | |
| end | |
| false | |
| end | |
| ... | |
| def search(query, current_pos, bads) | |
| return true if query == "" # it's here! | |
| return false unless @board[current_pos[0]][current_pos[1]] == query[0] | |
| possible_moves = possible_moves(current_pos, bads) | |
| possible_moves.each do |move| | |
| return true if search(query[1..-1], move, bads + move) | |
| end | |
| return false | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment