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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a6fde063384b381fd26d3bf8dd318e23ed68a76f2389bfe9ae5a25f6868106a
4
- data.tar.gz: dc16f5b1a5ad0e9e4d40f7cbb7bcb29fe9224ed9e39cd715e4fe42199cc6bd81
3
+ metadata.gz: 37a2b0b303c14b7f71edbfd175f86a25614a3fc103ba6d1870c02432d2d6010f
4
+ data.tar.gz: 336637bbb33eecf7647cc166aa98f0cd3e75e354346a9ac16a3f083a32c24412
5
5
  SHA512:
6
- metadata.gz: 63745922fe29a07bb57f3313328c5afb1ce1190cafec5b1d91a129075eaa7ee69de4799df60800711d76df2aeb364e5b7b46f94749ac6b1b72f8891c0e37aa8c
7
- data.tar.gz: 78b0c4fd62495d09a623815f8aa6410c65db0ac6d63ac8bfc8851d8932afffd2b87883716daa93c95b7482c56a2e3ec86cf5f4b9d39f68ecb5b206bd67380dbb
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wordle (0.4.0)
4
+ wordle (0.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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="794" alt="Screen Shot 2022-01-10 at 9 18 19 PM" src="https://user-images.githubusercontent.com/22665228/148885575-39805830-274e-40e6-be14-4c6bc6db37ec.png">
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
+ [![Build](https://github.com/JonathanWThom/wordle/actions/workflows/build.yml/badge.svg)](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 attempts < 6 && !winner
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 "Winner!"
43
+ puts "\nWordle Gem #{hash} #{guesses.length}/6\n\n"
46
44
  else
47
- puts "Word was: #{@target_word}"
48
- puts "Better luck next time!"
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
- @list.random
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
- target_letters = @target_word.chars
18
- guess_letters = @guess.chars
19
- colored_letters = []
20
-
21
- guess_letters.each_with_index do |letter, i|
22
- if letter == target_letters[i]
23
- colored_letters[i] = letter.green
24
- target_letters[i] = nil
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
- guess_letters.each_with_index do |letter, i|
29
- if colored_letters[i].nil?
30
- colored_letters[i] = if target_letters.include?(letter)
31
- letter.yellow
32
- else
33
- letter.gray
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
- colored_letters.join("")
62
+ colors
63
+ end
39
64
  end
40
65
  end
41
66
  end
data/lib/wordle/legend.rb CHANGED
@@ -10,6 +10,8 @@ module Wordle
10
10
  puts green_example
11
11
  puts yellow_example
12
12
  puts gray_example
13
+ puts "\nRestart and add -i flag to target a specific word by hash, for example:"
14
+ puts "$ wordle -i ed541a\n\n"
13
15
  end
14
16
 
15
17
  private
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wordle
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/wordle.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "digest"
4
+ require "optparse"
3
5
  require_relative "string"
4
6
  require_relative "wordle/version"
5
7
  require_relative "wordle/source"
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.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-01-15 00:00:00.000000000 Z
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.2.32
81
+ rubygems_version: 3.3.3
81
82
  signing_key:
82
83
  specification_version: 4
83
84
  summary: Wordle CLI in Ruby