Skip to content

Commit

Permalink
Added hint mode
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-crandall committed Jul 6, 2022
1 parent 042ab1e commit 892e5a2
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 6 deletions.
Empty file modified Readme.md
100644 → 100755
Empty file.
Empty file modified guess_word_list.txt
100644 → 100755
Empty file.
Empty file modified ordered_answers.txt
100644 → 100755
Empty file.
Empty file modified possible_answers.txt
100644 → 100755
Empty file.
Empty file modified possible_answers_small.txt
100644 → 100755
Empty file.
Empty file modified server.rb
100644 → 100755
Empty file.
Empty file modified server_test.rb
100644 → 100755
Empty file.
17 changes: 14 additions & 3 deletions solver.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require_relative './wordle.rb'
require_relative './server.rb'
require 'getoptlong'

opts = GetoptLong.new(
[ '--interactive', '-i', GetoptLong::NO_ARGUMENT ],
[ '--hint', '-h', GetoptLong::NO_ARGUMENT ],
[ '--date', '-d', GetoptLong::OPTIONAL_ARGUMENT ]
)

Expand All @@ -25,7 +27,15 @@ def interactive_mode
def find_word_date
@wordle = Wordle.new()
puts @wordle.word_date(@test_word)
exit!
end

def get_hint
wordle = Wordle.new()
server = Server.new("fluff")
(1..1).each do |i|
wordle.parse_answer(server.parse_guess(wordle.top_rated_word))
puts "Hint ##{i}: #{wordle.top_ten_words}"
end
end

opts.each do |opt, arg|
Expand All @@ -37,6 +47,9 @@ def find_word_date
@test_word = arg
find_word_date
exit!
when '--hint'
get_hint
exit!
end
end

Expand All @@ -55,5 +68,3 @@ def find_word_date
puts "How'd it do? (Y for yes, N for no, M for Maybe, xxxxx for not a word)"
@wordle.parse_answer(gets.chomp)
end


Empty file modified tester.rb
100644 → 100755
Empty file.
Empty file modified word_matcher.rb
100644 → 100755
Empty file.
16 changes: 13 additions & 3 deletions wordle.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative 'word_matcher'
require 'json'
require "date"
require 'date'

# rubocop:disable ClassLength
class Wordle
Expand All @@ -24,7 +24,7 @@ def top_rated_word

def top_ten_words
rate_words
@possibilities.sort_by { |_, v| -v }.first(10).to_h.keys
@possibilities.sort_by { |_, v| -v }.first(10).to_h.keys.shuffle
end

def found?
Expand All @@ -36,7 +36,12 @@ def broke?
end

def word_date(word)
Date.new(2021, 6, 19) + @ordered_word_list.index(word)
start_date + @ordered_word_list.index(word)
end

def todays_word
index = Date.today - start_date - 1
@ordered_word_list[index]
end

def guess(word)
Expand Down Expand Up @@ -358,6 +363,11 @@ def word_to_hash(word)
this_hash
end

# Date when wordle started
def start_date
@start_date ||= Date.new(2021, 6, 19)
end

def set_word_lists
@possible_answers = File.read('possible_answers.txt').split
@ordered_word_list = JSON.parse(File.read('ordered_answers.txt'))
Expand Down
Empty file modified wordle_test.rb
100644 → 100755
Empty file.

0 comments on commit 892e5a2

Please sign in to comment.