Class: Boggle::Solver

Inherits:
Object
  • Object
show all
Defined in:
lib/boggle/solver.rb

Instance Method Summary collapse

Constructor Details

#initialize(trie) ⇒ Solver

Returns a new instance of Solver.



7
8
9
10
# File 'lib/boggle/solver.rb', line 7

def initialize(trie)
  @found_words = {} # going to use it like a set
  @trie = trie
end

Instance Method Details

#in_trie?(prefix) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
# File 'lib/boggle/solver.rb', line 12

def in_trie?(prefix)
  if (d = @trie.match(prefix.upcase)) # not nil = okay
    if d.class == String
      @found_words[prefix] = d
    end
    true
  end
end

#solve(board) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/boggle/solver.rb', line 26

def solve(board)
  board.size.times do |row|
    board.size.times do |col|
      solve_frame(make_frame("", board, row, col))
    end
  end
end

#start(board) ⇒ Object



21
22
23
24
# File 'lib/boggle/solver.rb', line 21

def start(board)
  solve board
  @found_words
end