wordle 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.tool-versions +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +8 -1
- data/lib/wordle/game.rb +34 -11
- data/lib/wordle/guess_analyzer.rb +42 -17
- data/lib/wordle/legend.rb +2 -0
- data/lib/wordle/list.rb +10 -4
- data/lib/wordle/version.rb +1 -1
- data/lib/wordle.rb +2 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37a2b0b303c14b7f71edbfd175f86a25614a3fc103ba6d1870c02432d2d6010f
|
4
|
+
data.tar.gz: 336637bbb33eecf7647cc166aa98f0cd3e75e354346a9ac16a3f083a32c24412
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f20ad88e68d4fcdbdc5540905690cebb9018aea5dcc8e5f9aa3707aea9321a3579689e8aa0f5b21bd95375906c05135a5e819af33efa1cebfa754cdcbd5d657
|
7
|
+
data.tar.gz: 9eb4620e84138d2d87204fac907834b24cf41d431b5f4c36e546eb2f545465f8c2ebafae95f563cecf08a0b7f6822f1435d8d122dcf695cadba7ee4790a8660f
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.1.0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## [0.5.0] - 2022-02-02
|
2
|
+
|
3
|
+
- Prints outs squares for sharing at the end of a game.
|
4
|
+
- Sharing prints out unique hash for word that was played, which can be passed
|
5
|
+
to -i option so you can play the same word as a friend.
|
6
|
+
|
1
7
|
## [0.4.0] - 2022-01-14
|
2
8
|
|
3
9
|
- Fixes bug where too many letters would get marked as yellow. Resolves
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
Ruby implementation of [Wordle](https://www.powerlanguage.co.uk/wordle/).
|
4
4
|
|
5
|
-
<img width="
|
5
|
+
<img width="785" alt="Screen Shot 2022-01-14 at 8 10 22 PM" src="https://user-images.githubusercontent.com/22665228/149608330-f5514be8-c0d9-4860-9ed4-d652fdb35cb3.png">
|
6
|
+
|
7
|
+
[](https://github.com/JonathanWThom/wordle/actions/workflows/build.yml)
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -12,6 +14,11 @@ Ruby implementation of [Wordle](https://www.powerlanguage.co.uk/wordle/).
|
|
12
14
|
|
13
15
|
Just run `wordle` from the command line.
|
14
16
|
|
17
|
+
After the game, a hash will be included with your result. A friend can pass this
|
18
|
+
hash as the `-i` option to play the same word as you, e.g. `wordle -i ed541a`.
|
19
|
+
|
20
|
+
This version will pull a new word at random every time you run it from a very weird and long list. It's much more difficult than the original due to some of the words being a bit uncommon.
|
21
|
+
|
15
22
|
## Development
|
16
23
|
|
17
24
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/wordle/game.rb
CHANGED
@@ -8,20 +8,18 @@ module Wordle
|
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@list = List.new
|
11
|
+
@options = read_options
|
11
12
|
@target_word = generate_word
|
12
13
|
end
|
13
14
|
|
14
|
-
# print letters that have already been used?
|
15
|
-
# compare to real words
|
16
|
-
|
17
15
|
def play
|
18
16
|
winner = false
|
19
|
-
attempts = 0
|
20
17
|
|
21
18
|
Legend.print
|
22
19
|
puts "Guess a 5 letter word: "
|
20
|
+
guesses = []
|
23
21
|
|
24
|
-
while
|
22
|
+
while guesses.length < 6 && !winner
|
25
23
|
guess = gets.chomp
|
26
24
|
|
27
25
|
validator = GuessValidator.new(guess, @list)
|
@@ -32,27 +30,52 @@ module Wordle
|
|
32
30
|
|
33
31
|
analyzer = GuessAnalyzer.new(@target_word, guess)
|
34
32
|
puts analyzer.colors
|
33
|
+
guesses << analyzer.squares
|
35
34
|
|
36
35
|
if analyzer.match?
|
37
36
|
winner = true
|
38
37
|
break
|
39
38
|
end
|
40
|
-
|
41
|
-
attempts += 1
|
42
39
|
end
|
43
40
|
|
41
|
+
hash = Digest::SHA2.hexdigest(@target_word)[..5]
|
44
42
|
if winner
|
45
|
-
puts "
|
43
|
+
puts "\nWordle Gem #{hash} #{guesses.length}/6\n\n"
|
46
44
|
else
|
47
|
-
puts "
|
48
|
-
puts "
|
45
|
+
puts "\nWord was: #{@target_word}\n"
|
46
|
+
puts "\nWordle Gem #{hash} X/6*\n\n"
|
49
47
|
end
|
48
|
+
|
49
|
+
puts guesses
|
50
50
|
end
|
51
51
|
|
52
52
|
private
|
53
53
|
|
54
54
|
def generate_word
|
55
|
-
@
|
55
|
+
if @options[:identifier]
|
56
|
+
@list.by_hash(@options[:identifier])
|
57
|
+
else
|
58
|
+
@list.random
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def read_options
|
63
|
+
options = {}
|
64
|
+
parser = OptionParser.new do |opts|
|
65
|
+
opts.banner = "Usage: wordle [options]"
|
66
|
+
|
67
|
+
opts.on("-iIDENTIFIER", "--identifier=IDENTIFIER", "Pass word identifer to target a specific word that someone else has played. Identifier gets printed at the end of the game to share.") do |i|
|
68
|
+
options[:identifier] = i
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
begin
|
73
|
+
parser.parse!
|
74
|
+
rescue OptionParser::InvalidOption
|
75
|
+
puts "Option not recognized"
|
76
|
+
end
|
77
|
+
|
78
|
+
options
|
56
79
|
end
|
57
80
|
end
|
58
81
|
end
|
@@ -14,28 +14,53 @@ module Wordle
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def colors
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
raw_colors.each_with_index.map do |color, i|
|
18
|
+
guess_letters[i].send(color)
|
19
|
+
end.join("")
|
20
|
+
end
|
21
|
+
|
22
|
+
def squares
|
23
|
+
color_map = {
|
24
|
+
green: "🟩",
|
25
|
+
yellow: "🟨",
|
26
|
+
gray: "⬛️"
|
27
|
+
}
|
28
|
+
|
29
|
+
raw_colors.each_with_index.map do |color, i|
|
30
|
+
color_map[color]
|
31
|
+
end.join("")
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def guess_letters
|
37
|
+
@_guess_letters = @guess.chars
|
38
|
+
end
|
39
|
+
|
40
|
+
def raw_colors
|
41
|
+
@_raw_colors ||= begin
|
42
|
+
target_letters = @target_word.chars
|
43
|
+
colors = []
|
44
|
+
|
45
|
+
guess_letters.each_with_index do |letter, i|
|
46
|
+
if letter == target_letters[i]
|
47
|
+
colors[i] = :green
|
48
|
+
target_letters[i] = nil
|
49
|
+
end
|
25
50
|
end
|
26
|
-
end
|
27
51
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
52
|
+
guess_letters.each_with_index do |letter, i|
|
53
|
+
if colors[i].nil?
|
54
|
+
colors[i] = if target_letters.include?(letter)
|
55
|
+
:yellow
|
56
|
+
else
|
57
|
+
:gray
|
58
|
+
end
|
34
59
|
end
|
35
60
|
end
|
36
|
-
end
|
37
61
|
|
38
|
-
|
62
|
+
colors
|
63
|
+
end
|
39
64
|
end
|
40
65
|
end
|
41
66
|
end
|
data/lib/wordle/legend.rb
CHANGED
data/lib/wordle/list.rb
CHANGED
@@ -2,14 +2,20 @@
|
|
2
2
|
|
3
3
|
module Wordle
|
4
4
|
class List
|
5
|
-
def initialize(length = 5)
|
6
|
-
@length = length
|
7
|
-
end
|
8
|
-
|
9
5
|
def random
|
10
6
|
list.sample.downcase.strip
|
11
7
|
end
|
12
8
|
|
9
|
+
def by_hash(hash)
|
10
|
+
word = list.detect do |word|
|
11
|
+
Digest::SHA2.hexdigest(word.downcase.strip)[..5] == hash
|
12
|
+
end
|
13
|
+
|
14
|
+
raise Wordle::Error, "Invalid word identifier, are you sure you copied it correctly?" if word.nil?
|
15
|
+
|
16
|
+
word
|
17
|
+
end
|
18
|
+
|
13
19
|
def invalid?(word)
|
14
20
|
!list.include?(word)
|
15
21
|
end
|
data/lib/wordle/version.rb
CHANGED
data/lib/wordle.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wordle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Thom
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: debug
|
@@ -34,6 +34,7 @@ extra_rdoc_files: []
|
|
34
34
|
files:
|
35
35
|
- ".rspec"
|
36
36
|
- ".standard.yml"
|
37
|
+
- ".tool-versions"
|
37
38
|
- CHANGELOG.md
|
38
39
|
- CODE_OF_CONDUCT.md
|
39
40
|
- Gemfile
|
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
78
|
- !ruby/object:Gem::Version
|
78
79
|
version: '0'
|
79
80
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
81
|
+
rubygems_version: 3.3.3
|
81
82
|
signing_key:
|
82
83
|
specification_version: 4
|
83
84
|
summary: Wordle CLI in Ruby
|