Sha256: b6b907c35ef37186862fab3a817eeef3b71b002e1d25560a806b1b9a9ea320c2
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
require 'letter_press_is_not_as_good_as_boggle/board_traverser' require 'letter_press_is_not_as_good_as_boggle/word_list' require 'letter_press_is_not_as_good_as_boggle/word_list/searcher' require 'set' def LetterPressIsNotAsGoodAsBoggle(&block) LetterPressIsNotAsGoodAsBoggle.new(&block).words end class LetterPressIsNotAsGoodAsBoggle def self.all_words File.read(File.expand_path '../../data/word_list', __FILE__).split("\n") end def initialize(all_words=LetterPressIsNotAsGoodAsBoggle.all_words, &definition) @guessed = [] self.searcher = WordList::Searcher.new WordList.new all_words instance_eval &definition end def board(chars) self.chars = chars end def guessed(guessed=[]) @guessed = guessed end alias guesses guessed # to maintain backwards compatibility def words @words ||= begin words = Set.new board_traverser.each_with_recur do |word, char, recurser| next unless searcher.has_child? char searcher.down_to char do words << word if searcher.on_word? && !@guessed.include?(word) recurser.call end end words.sort_by &:length end end private attr_accessor :chars, :searcher def board_traverser @board_traverser ||= BoardTraverser.new chars end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
letter_press_is_not_as_good_as_boggle-1.0.2 | lib/letter_press_is_not_as_good_as_boggle.rb |