wordle 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +8 -5
- data/lib/integer.rb +13 -0
- data/lib/wordle/game.rb +17 -24
- data/lib/wordle/guess_analyzer.rb +21 -3
- data/lib/wordle/guess_validator.rb +46 -7
- data/lib/wordle/options.rb +29 -0
- data/lib/wordle/version.rb +1 -1
- data/lib/wordle.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4aa10bd48df4f525022634f4a41a1c4009f25e6da6bd9992470c2c963f08a91c
|
4
|
+
data.tar.gz: 99047acbf6078ca14d65aaaf71d0727fbb489557d58c72ed02c41d67bbb9b22e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a807bcfa10a95e25cb272da8d28a8bd65172e3d623ba76f8e0bc98fd8e4f8618e205a18b6ead77c79e3c21171b6801e64c729029cdbbd9615d713cef53767a87
|
7
|
+
data.tar.gz: 3e44a8f3ed4eb337de645d60d50399393206d56df15e29262d6a327ae52c3b2edf6dd8e9daee3eeaffb05d66470916cddf518113d2c4d0fb1a0eca720e976db0
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Ruby implementation of [Wordle](https://www.powerlanguage.co.uk/wordle/).
|
4
4
|
|
5
|
-
<img width="
|
5
|
+
<img width="869" alt="Screen Shot 2022-02-02 at 10 32 02 PM" src="https://user-images.githubusercontent.com/22665228/152292863-33743039-d9f4-4afa-a321-684d7b67cdb3.png">
|
6
6
|
|
7
7
|
[![Build](https://github.com/JonathanWThom/wordle/actions/workflows/build.yml/badge.svg)](https://github.com/JonathanWThom/wordle/actions/workflows/build.yml)
|
8
8
|
|
@@ -14,11 +14,14 @@ Ruby implementation of [Wordle](https://www.powerlanguage.co.uk/wordle/).
|
|
14
14
|
|
15
15
|
Just run `wordle` from the command line.
|
16
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
17
|
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
18
|
|
19
|
+
```
|
20
|
+
Usage: wordle [options]
|
21
|
+
-i, --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 with a friend.
|
22
|
+
-d, --difficult Hard mode. Any revealed hints must be used in subsequent guesses.
|
23
|
+
```
|
24
|
+
|
22
25
|
## Development
|
23
26
|
|
24
27
|
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.
|
@@ -31,7 +34,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Jonath
|
|
31
34
|
|
32
35
|
## Acknowledgements
|
33
36
|
|
34
|
-
I cribbed my word list from the Wordle site itself. I have no association with the site
|
37
|
+
I cribbed my word list from the Wordle site itself. I have no association with the site, its creator, or the New York Times - I'm just a fan!
|
35
38
|
|
36
39
|
## License
|
37
40
|
|
data/lib/integer.rb
ADDED
data/lib/wordle/game.rb
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
module Wordle
|
4
4
|
class Game
|
5
|
-
def self.play
|
6
|
-
new.play
|
5
|
+
def self.play(*args)
|
6
|
+
new(*args).play
|
7
7
|
end
|
8
8
|
|
9
|
-
def initialize
|
9
|
+
def initialize(options_reader = Options.new)
|
10
10
|
@list = List.new
|
11
|
-
@options =
|
11
|
+
@options = options_reader.read
|
12
12
|
@target_word = generate_word
|
13
13
|
end
|
14
14
|
|
@@ -18,11 +18,19 @@ module Wordle
|
|
18
18
|
Legend.print
|
19
19
|
puts "Guess a 5 letter word: "
|
20
20
|
guesses = []
|
21
|
+
must_include = []
|
22
|
+
must_match = Array.new(5)
|
21
23
|
|
22
24
|
while guesses.length < 6 && !winner
|
23
25
|
guess = gets.chomp
|
24
26
|
|
25
|
-
validator = GuessValidator.new(
|
27
|
+
validator = GuessValidator.new(
|
28
|
+
guess,
|
29
|
+
@list,
|
30
|
+
@options[:difficult],
|
31
|
+
must_include,
|
32
|
+
must_match
|
33
|
+
)
|
26
34
|
if validator.invalid?
|
27
35
|
puts validator.error
|
28
36
|
next
|
@@ -31,6 +39,10 @@ module Wordle
|
|
31
39
|
analyzer = GuessAnalyzer.new(@target_word, guess)
|
32
40
|
puts analyzer.colors
|
33
41
|
guesses << analyzer.squares
|
42
|
+
if @options[:difficult]
|
43
|
+
must_include = analyzer.must_include(must_include)
|
44
|
+
must_match = analyzer.must_match(must_match)
|
45
|
+
end
|
34
46
|
|
35
47
|
if analyzer.match?
|
36
48
|
winner = true
|
@@ -58,24 +70,5 @@ module Wordle
|
|
58
70
|
@list.random
|
59
71
|
end
|
60
72
|
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
|
79
|
-
end
|
80
73
|
end
|
81
74
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../string"
|
4
|
-
|
5
3
|
module Wordle
|
6
4
|
class GuessAnalyzer
|
7
5
|
def initialize(target_word, guess)
|
@@ -31,10 +29,30 @@ module Wordle
|
|
31
29
|
end.join("")
|
32
30
|
end
|
33
31
|
|
32
|
+
def must_include(prev_must_include)
|
33
|
+
raw_colors.each_with_index do |color, i|
|
34
|
+
if color == :yellow && !prev_must_include.include?(guess_letters[i])
|
35
|
+
prev_must_include << guess_letters[i]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
prev_must_include
|
40
|
+
end
|
41
|
+
|
42
|
+
def must_match(prev_must_match)
|
43
|
+
raw_colors.each_with_index do |color, i|
|
44
|
+
if color == :green
|
45
|
+
prev_must_match[i] = guess_letters[i]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
prev_must_match
|
50
|
+
end
|
51
|
+
|
34
52
|
private
|
35
53
|
|
36
54
|
def guess_letters
|
37
|
-
@_guess_letters
|
55
|
+
@_guess_letters ||= @guess.chars
|
38
56
|
end
|
39
57
|
|
40
58
|
def raw_colors
|
@@ -2,23 +2,62 @@
|
|
2
2
|
|
3
3
|
module Wordle
|
4
4
|
class GuessValidator
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def initialize(
|
6
|
+
guess,
|
7
|
+
list,
|
8
|
+
difficult,
|
9
|
+
must_include,
|
10
|
+
must_match
|
11
|
+
)
|
8
12
|
@guess = guess
|
9
13
|
@list = list
|
14
|
+
@difficult = difficult
|
15
|
+
@must_include = must_include
|
16
|
+
@must_match = must_match
|
17
|
+
@validated = false
|
10
18
|
end
|
11
19
|
|
12
20
|
def invalid?
|
21
|
+
!error.nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
def error
|
25
|
+
validate if !@validated
|
26
|
+
|
27
|
+
@error
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def validate
|
33
|
+
validate_normal_mode
|
34
|
+
validate_hard_mode if @difficult
|
35
|
+
@validated = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_normal_mode
|
13
39
|
if @guess.length != 5
|
14
40
|
@error = "Guess must be 5 letters long"
|
15
|
-
return true
|
16
41
|
elsif @list.invalid?(@guess)
|
17
|
-
@error = "Guess
|
18
|
-
|
42
|
+
@error = "Guess not in word list"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_hard_mode
|
47
|
+
@must_include.each do |letter|
|
48
|
+
if !@guess.include?(letter)
|
49
|
+
@error = "Guess must include #{letter}"
|
50
|
+
break
|
51
|
+
end
|
19
52
|
end
|
20
53
|
|
21
|
-
|
54
|
+
@guess.each_char.with_index do |letter, i|
|
55
|
+
match = @must_match[i]
|
56
|
+
if match && match != letter
|
57
|
+
@error = "#{(i + 1).ordinalize} letter must be #{match}"
|
58
|
+
break
|
59
|
+
end
|
60
|
+
end
|
22
61
|
end
|
23
62
|
end
|
24
63
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wordle
|
4
|
+
class Options
|
5
|
+
def read
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: wordle [options]"
|
10
|
+
|
11
|
+
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 with a friend.") do |i|
|
12
|
+
options[:identifier] = i
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on("-d", "--difficult", "Hard mode. Any revealed hints must be used in subsequent guesses.") do |d|
|
16
|
+
options[:difficult] = d
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
begin
|
21
|
+
parser.parse!
|
22
|
+
rescue OptionParser::InvalidOption
|
23
|
+
puts "Option not recognized"
|
24
|
+
end
|
25
|
+
|
26
|
+
options
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/wordle/version.rb
CHANGED
data/lib/wordle.rb
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
|
3
3
|
require "digest"
|
4
4
|
require "optparse"
|
5
|
+
require_relative "integer"
|
5
6
|
require_relative "string"
|
6
7
|
require_relative "wordle/version"
|
8
|
+
require_relative "wordle/options"
|
7
9
|
require_relative "wordle/source"
|
8
10
|
require_relative "wordle/list"
|
9
11
|
require_relative "wordle/guess_validator"
|
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.6.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-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: debug
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- bin/console
|
46
46
|
- bin/setup
|
47
47
|
- exe/wordle
|
48
|
+
- lib/integer.rb
|
48
49
|
- lib/string.rb
|
49
50
|
- lib/wordle.rb
|
50
51
|
- lib/wordle/game.rb
|
@@ -52,6 +53,7 @@ files:
|
|
52
53
|
- lib/wordle/guess_validator.rb
|
53
54
|
- lib/wordle/legend.rb
|
54
55
|
- lib/wordle/list.rb
|
56
|
+
- lib/wordle/options.rb
|
55
57
|
- lib/wordle/source.rb
|
56
58
|
- lib/wordle/version.rb
|
57
59
|
- wordle.gemspec
|