wordle_decoder 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b287c675238c8e02b76dd2fcb7c6811837831e2245954a9465a2f1d6634ecb5
4
- data.tar.gz: 1d0f11cdd67b6443ebc6362daf666e82006c361b23a9847ee8c1a3020eeea1ad
3
+ metadata.gz: 61618c17d27aec3ae0fc68ea34e5f316d050d72e556e5ab7c972871649a3e4d2
4
+ data.tar.gz: 6545c2ad4fc4113a210b2b8e5809827327ef0830bfafaaf9f9aa141c0706df4f
5
5
  SHA512:
6
- metadata.gz: 4dcdc6aa0b31fd576fc973bd35ff7681ae4e054009d62f81afa00a25088e06e81e4c128068de5c524d4e30668b49bd0847e2354f5f614e80fab0e48a7c56c75d
7
- data.tar.gz: d414927380ff8e1832c7eb70b1e9f632dc41357d586f1f9674cda5f8161e0d6e2c3ff393677b45fab47155d2b56dac1f6edf4a446003da4b4b2fdbf2399af6aa
6
+ metadata.gz: f03be54869ded6a7a8364e9ecc30c23f755ce093b30f8b92f6075774ea160962fe40fd190ecc8061e71752ed41d26b5f91fe5729809ba4920650500b1d0ab9e6
7
+ data.tar.gz: 440b20a14eba2632a58ab7f79a78075f2798420f695540e269fbdcb9590f00ae7a2d21e6ac5c5c3e26ad0ea3b365c60639eb637827100b64e72ffe9b3abfd808
data/CHANGELOG.md CHANGED
@@ -1,8 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.5] - 2022-03-20
4
+
5
+ - Support high contrast mode - https://github.com/mattruzicka/wordle_decoder/issues/4
6
+ - Fix edge case where words were being falsey considered impossible when containing more than one of the same letter which is in the answer - https://github.com/mattruzicka/wordle_decoder/issues/3
7
+ - Found some old notes/TODOs I took while on a walk and forgot about [4201916](https://github.com/mattruzicka/wordle_decoder/commit/4201916b47f84ba7ee851db938b8dba36eb64236)
8
+
3
9
  ## [0.1.4] - 2022-03-06
4
10
 
5
- - Deal with weird input chars - https://github.com/mattruzicka/wordle_decoder/issues/2
11
+ - Deal with weird input chars - https://github.com/mattruzicka/wordle_decoder/issues/2
6
12
 
7
13
  ## [0.1.3] - 2022-03-05
8
14
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wordle_decoder (0.1.3)
4
+ wordle_decoder (0.1.5)
5
5
  cli-ui (~> 1.5)
6
6
 
7
7
  GEM
data/bin/wordle_decoder CHANGED
@@ -134,6 +134,9 @@ salutations = ["Maybe some of those are your words!",
134
134
  "What lovely words you have!",
135
135
  "I hope my words were as good as yours!",
136
136
  "Please enjoy the rest of your day!",
137
+ "I hope that what I'm lacking in precision is made up in personality.",
138
+ "I see your love of the game.",
139
+ "Wanna exchange five letter words?",
137
140
  "I may not be positive about your words, but I am about you!",
138
141
  "Thank you for spending time with me!",
139
142
  "I enjoyed our time together!"].freeze
@@ -9,19 +9,19 @@ class WordleDecoder
9
9
  end
10
10
 
11
11
  def score
12
- @score ||= words_with_scores.sum(&:last)
12
+ @score ||= best_words_with_scores.sum(&:last)
13
13
  end
14
14
 
15
15
  def word_scores
16
- @word_scores ||= words_with_scores.map(&:last)
16
+ @word_scores ||= best_words_with_scores.map(&:last)
17
17
  end
18
18
 
19
19
  def words
20
- @words ||= words_with_scores.map { |w, _s| w.to_s }
20
+ @words ||= best_words_with_scores.map { |w, _s| w.to_s }
21
21
  end
22
22
 
23
- def words_with_scores
24
- @words_with_scores ||= select_words_with_scores
23
+ def best_words_with_scores
24
+ @best_words_with_scores ||= select_best_words_with_scores
25
25
  end
26
26
 
27
27
  def inspect
@@ -30,18 +30,7 @@ class WordleDecoder
30
30
 
31
31
  private
32
32
 
33
- #
34
- # Greatly penalize words that have multiple of the same black letters
35
- # Greatly penalize words that have the same black letters as any seen word
36
- # Greatly penalize words that have the same yellow letter/index pair as any seen word
37
- # Reward words that have yellow letters that match yellow letters in seen words, but in different positions
38
- # Reward words that have yellow letters that match green letters in seen words
39
- # Penalize words that have yellow letters that don't appear in seen words
40
- # Penalize words that have green letters that don't appear in seen words
41
- # Rewards words based on commonality
42
- # Reward/penalize words based on line indexes and common letters
43
- #
44
- def select_words_with_scores
33
+ def select_best_words_with_scores
45
34
  selected_words = [@start_word]
46
35
  selected_word_scores = [@start_word.score]
47
36
  seen_black_chars = @start_word.black_chars
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class WordleDecoder
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -5,7 +5,9 @@ class WordleDecoder
5
5
  EMOJI_HINT_CHARS = { "⬛" => "b",
6
6
  "⬜" => "b",
7
7
  "🟨" => "y",
8
- "🟩" => "g" }.freeze
8
+ "🟦" => "y",
9
+ "🟩" => "g",
10
+ "🟧" => "g" }.freeze
9
11
 
10
12
  def initialize(hint_line, line_index, answer_chars)
11
13
  @hint_chars = normalize_hint_chars(hint_line)
@@ -143,7 +145,21 @@ class WordleDecoder
143
145
  end
144
146
 
145
147
  def impossible_words(commonality)
146
- WordSearch.chars_at_index(@answer_chars, @index, commonality)
148
+ words = WordSearch.chars_at_index(@answer_chars, @index, commonality)
149
+ reject_possible_words_where_letter_appears_multiple_times_and_is_in_answer!(words)
150
+ words
151
+ end
152
+
153
+ private
154
+
155
+ def reject_possible_words_where_letter_appears_multiple_times_and_is_in_answer!(words)
156
+ words.reject! do |word|
157
+ chars = word.chars
158
+ index_char = chars[@index]
159
+ chars.each_with_index.any? do |char, idx|
160
+ char == index_char && idx != @index && @answer_chars.include?(char)
161
+ end
162
+ end
147
163
  end
148
164
  end
149
165
  end
@@ -3,11 +3,27 @@
3
3
  class WordleDecoder
4
4
  class WordleShare
5
5
  ANSWER_LINES = ["🟩🟩🟩🟩🟩",
6
- "ggggg",
7
- ":large_green_square:" * 5].freeze
6
+ "🟧🟧🟧🟧🟧"].freeze
8
7
 
9
- def self.final_line?(input_lines)
10
- ANSWER_LINES.any? { input_lines.include?(_1) }
8
+ def self.final_line?(input_line)
9
+ line = normalize_wordle_line(input_line.strip)
10
+ ANSWER_LINES.include?(line)
11
+ end
12
+
13
+ def self.normalize_wordle_line(line)
14
+ line = translate_emoji_shortcodes(line)
15
+ line.each_grapheme_cluster.map { |cluster| cluster.codepoints.first }.pack("U*")
16
+ end
17
+
18
+ SHORTCODES_TO_EMOJIS = { ":black_large_square:" => "⬛",
19
+ ":white_large_square:" => "⬜",
20
+ ":large_green_square:" => "🟩",
21
+ ":large_yellow_square:" => "🟨",
22
+ ":large_orange_square:" => "🟧",
23
+ ":large_blue_square:" => "🟦" }.freeze
24
+
25
+ def self.translate_emoji_shortcodes(line)
26
+ SHORTCODES_TO_EMOJIS.reduce(line) { |acc, (key, val)| acc.gsub(key, val) }
11
27
  end
12
28
 
13
29
  NEEDS_HELP_INPUTS = %w[help what wordle wat ? man okay yes no test].freeze
@@ -102,25 +118,11 @@ class WordleDecoder
102
118
 
103
119
  def parse_wordle_lines!
104
120
  input_lines.filter_map do |line|
105
- line = normalize_wordle_line(line)
121
+ line = self.class.normalize_wordle_line(line)
106
122
  line if line.each_char.all? { |c| VALID_HINT_CHARS.include?(c) }
107
123
  end
108
124
  end
109
125
 
110
- def normalize_wordle_line(line)
111
- line = translate_emoji_shortcodes(line)
112
- line.each_grapheme_cluster.map { |cluster| cluster.codepoints.first }.pack("U*")
113
- end
114
-
115
- SHORTCODES_TO_EMOJIS = { ":black_large_square:" => "⬛",
116
- ":white_large_square:" => "⬜",
117
- ":large_green_square:" => "🟩",
118
- ":large_yellow_square:" => "🟨" }.freeze
119
-
120
- def translate_emoji_shortcodes(line)
121
- SHORTCODES_TO_EMOJIS.reduce(line) { |acc, (key, val)| acc.gsub(key, val) }
122
- end
123
-
124
126
  def parse_input_lines!
125
127
  case input
126
128
  when String
@@ -36,7 +36,7 @@ class WordleDecoder
36
36
 
37
37
  def to_terminal
38
38
  str = +"\n"
39
- best_guess.words_with_scores.reverse_each do |word, guess_score|
39
+ best_guess.best_words_with_scores.reverse_each do |word, guess_score|
40
40
  str << " #{word.to_terminal} #{word.confidence_score(guess_score)}\n"
41
41
  end
42
42
  str << " {{green:#{@wordle_share.answer}}}\n"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordle_decoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Ruzicka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-06 00:00:00.000000000 Z
11
+ date: 2022-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cli-ui