wordle 0.6.0 → 0.7.0

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: 4aa10bd48df4f525022634f4a41a1c4009f25e6da6bd9992470c2c963f08a91c
4
- data.tar.gz: 99047acbf6078ca14d65aaaf71d0727fbb489557d58c72ed02c41d67bbb9b22e
3
+ metadata.gz: 5fa86fa80e845caca00f5128d21a4c569996441d57b9367862a1a634067052d3
4
+ data.tar.gz: a3965aea2dba04cf9abfd4a8bc1e1760980630200f576d60bf7b14319aace3a3
5
5
  SHA512:
6
- metadata.gz: a807bcfa10a95e25cb272da8d28a8bd65172e3d623ba76f8e0bc98fd8e4f8618e205a18b6ead77c79e3c21171b6801e64c729029cdbbd9615d713cef53767a87
7
- data.tar.gz: 3e44a8f3ed4eb337de645d60d50399393206d56df15e29262d6a327ae52c3b2edf6dd8e9daee3eeaffb05d66470916cddf518113d2c4d0fb1a0eca720e976db0
6
+ metadata.gz: 9f1772bbf2e003583cf25ee27af46f2911ff584dfa4c4e2533aafeaa411ba877db690d4f4789242a50e9c54a070beea66e3db966ed4aa0a84075b431977be10c
7
+ data.tar.gz: 87f7b5e53311ee0e15f1cacf56f2eaae014ea1a78ce0363f590ee9a4c273b4717bf13f748864dbe67ab567d0862c881fe69f62b2adec8a1c579921b451d9aa74
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.1.0
1
+ ruby 3.1.1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.7.0] - 2022-04-15
2
+
3
+ - Adds high color contrast mode.
4
+
1
5
  ## [0.6.0] - 2022-04-14
2
6
 
3
7
  - Adds hard mode.
data/Gemfile CHANGED
@@ -5,8 +5,8 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in wordle.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem "rake"
9
9
 
10
- gem "rspec", "~> 3.0"
10
+ gem "rspec"
11
11
 
12
- gem "standard", "~> 1.3"
12
+ gem "standard"
data/Gemfile.lock CHANGED
@@ -1,71 +1,70 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wordle (0.6.0)
4
+ wordle (0.7.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
- debug (1.4.0)
10
+ debug (1.5.0)
11
11
  irb (>= 1.3.6)
12
12
  reline (>= 0.2.7)
13
13
  diff-lcs (1.5.0)
14
14
  io-console (0.5.11)
15
15
  irb (1.4.1)
16
16
  reline (>= 0.3.0)
17
- parallel (1.21.0)
18
- parser (3.1.0.0)
17
+ parallel (1.22.1)
18
+ parser (3.1.2.0)
19
19
  ast (~> 2.4.1)
20
- rainbow (3.0.0)
20
+ rainbow (3.1.1)
21
21
  rake (13.0.6)
22
- regexp_parser (2.2.0)
22
+ regexp_parser (2.3.0)
23
23
  reline (0.3.1)
24
24
  io-console (~> 0.5)
25
25
  rexml (3.2.5)
26
- rspec (3.10.0)
27
- rspec-core (~> 3.10.0)
28
- rspec-expectations (~> 3.10.0)
29
- rspec-mocks (~> 3.10.0)
30
- rspec-core (3.10.1)
31
- rspec-support (~> 3.10.0)
32
- rspec-expectations (3.10.1)
26
+ rspec (3.11.0)
27
+ rspec-core (~> 3.11.0)
28
+ rspec-expectations (~> 3.11.0)
29
+ rspec-mocks (~> 3.11.0)
30
+ rspec-core (3.11.0)
31
+ rspec-support (~> 3.11.0)
32
+ rspec-expectations (3.11.0)
33
33
  diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.10.0)
35
- rspec-mocks (3.10.2)
34
+ rspec-support (~> 3.11.0)
35
+ rspec-mocks (3.11.1)
36
36
  diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.10.0)
38
- rspec-support (3.10.3)
39
- rubocop (1.24.1)
37
+ rspec-support (~> 3.11.0)
38
+ rspec-support (3.11.0)
39
+ rubocop (1.27.0)
40
40
  parallel (~> 1.10)
41
- parser (>= 3.0.0.0)
41
+ parser (>= 3.1.0.0)
42
42
  rainbow (>= 2.2.2, < 4.0)
43
43
  regexp_parser (>= 1.8, < 3.0)
44
44
  rexml
45
- rubocop-ast (>= 1.15.1, < 2.0)
45
+ rubocop-ast (>= 1.16.0, < 2.0)
46
46
  ruby-progressbar (~> 1.7)
47
47
  unicode-display_width (>= 1.4.0, < 3.0)
48
- rubocop-ast (1.15.1)
49
- parser (>= 3.0.1.1)
50
- rubocop-performance (1.13.1)
48
+ rubocop-ast (1.17.0)
49
+ parser (>= 3.1.1.0)
50
+ rubocop-performance (1.13.3)
51
51
  rubocop (>= 1.7.0, < 2.0)
52
52
  rubocop-ast (>= 0.4.0)
53
53
  ruby-progressbar (1.11.0)
54
- standard (1.6.0)
55
- rubocop (= 1.24.1)
56
- rubocop-performance (= 1.13.1)
54
+ standard (1.10.0)
55
+ rubocop (= 1.27.0)
56
+ rubocop-performance (= 1.13.3)
57
57
  unicode-display_width (2.1.0)
58
58
 
59
59
  PLATFORMS
60
60
  x86_64-darwin-21
61
- x86_64-linux
62
61
 
63
62
  DEPENDENCIES
64
63
  debug (>= 1.0.0)
65
- rake (~> 13.0)
66
- rspec (~> 3.0)
67
- standard (~> 1.3)
64
+ rake
65
+ rspec
66
+ standard
68
67
  wordle!
69
68
 
70
69
  BUNDLED WITH
71
- 2.3.4
70
+ 2.3.7
data/README.md CHANGED
@@ -20,6 +20,7 @@ This version will pull a new word at random every time you run it from a very we
20
20
  Usage: wordle [options]
21
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
22
  -d, --difficult Hard mode. Any revealed hints must be used in subsequent guesses.
23
+ -c, --contrast High contrast mode. Matched letters will be orange. Included letters will be blue.
23
24
  ```
24
25
 
25
26
  ## Development
data/lib/string.rb CHANGED
@@ -14,4 +14,12 @@ class String
14
14
  def gray
15
15
  colorize(47)
16
16
  end
17
+
18
+ def blue
19
+ colorize(46)
20
+ end
21
+
22
+ def orange
23
+ "\033[48:2:255:165:0m#{self}\033[m"
24
+ end
17
25
  end
data/lib/wordle/game.rb CHANGED
@@ -10,12 +10,13 @@ module Wordle
10
10
  @list = List.new
11
11
  @options = options_reader.read
12
12
  @target_word = generate_word
13
+ @result_builder = ResultBuilder.new(@options[:contrast])
13
14
  end
14
15
 
15
16
  def play
16
17
  winner = false
17
18
 
18
- Legend.print
19
+ Legend.print(@result_builder)
19
20
  puts "Guess a 5 letter word: "
20
21
  guesses = []
21
22
  must_include = []
@@ -36,7 +37,11 @@ module Wordle
36
37
  next
37
38
  end
38
39
 
39
- analyzer = GuessAnalyzer.new(@target_word, guess)
40
+ analyzer = GuessAnalyzer.new(
41
+ @target_word,
42
+ guess,
43
+ @result_builder
44
+ )
40
45
  puts analyzer.colors
41
46
  guesses << analyzer.squares
42
47
  if @options[:difficult]
@@ -2,9 +2,10 @@
2
2
 
3
3
  module Wordle
4
4
  class GuessAnalyzer
5
- def initialize(target_word, guess)
5
+ def initialize(target_word, guess, result_builder = ResultBuilder.new)
6
6
  @target_word = target_word
7
7
  @guess = guess
8
+ @result_builder = result_builder
8
9
  end
9
10
 
10
11
  def match?
@@ -12,26 +13,20 @@ module Wordle
12
13
  end
13
14
 
14
15
  def colors
15
- raw_colors.each_with_index.map do |color, i|
16
- guess_letters[i].send(color)
16
+ raw_results.each_with_index.map do |result, i|
17
+ guess_letters[i].send(@result_builder.text_color(result))
17
18
  end.join("")
18
19
  end
19
20
 
20
21
  def squares
21
- color_map = {
22
- green: "🟩",
23
- yellow: "🟨",
24
- gray: "⬛️"
25
- }
26
-
27
- raw_colors.each_with_index.map do |color, i|
28
- color_map[color]
22
+ raw_results.each_with_index.map do |result, i|
23
+ @result_builder.square(result)
29
24
  end.join("")
30
25
  end
31
26
 
32
27
  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])
28
+ raw_results.each_with_index do |result, i|
29
+ if @result_builder.included?(result) && !prev_must_include.include?(guess_letters[i])
35
30
  prev_must_include << guess_letters[i]
36
31
  end
37
32
  end
@@ -40,8 +35,8 @@ module Wordle
40
35
  end
41
36
 
42
37
  def must_match(prev_must_match)
43
- raw_colors.each_with_index do |color, i|
44
- if color == :green
38
+ raw_results.each_with_index do |result, i|
39
+ if @result_builder.match?(result)
45
40
  prev_must_match[i] = guess_letters[i]
46
41
  end
47
42
  end
@@ -55,29 +50,29 @@ module Wordle
55
50
  @_guess_letters ||= @guess.chars
56
51
  end
57
52
 
58
- def raw_colors
59
- @_raw_colors ||= begin
53
+ def raw_results
54
+ @_raw_results ||= begin
60
55
  target_letters = @target_word.chars
61
- colors = []
56
+ results = []
62
57
 
63
58
  guess_letters.each_with_index do |letter, i|
64
59
  if letter == target_letters[i]
65
- colors[i] = :green
60
+ results[i] = @result_builder.match
66
61
  target_letters[i] = nil
67
62
  end
68
63
  end
69
64
 
70
65
  guess_letters.each_with_index do |letter, i|
71
- if colors[i].nil?
72
- colors[i] = if target_letters.include?(letter)
73
- :yellow
66
+ if results[i].nil?
67
+ results[i] = if target_letters.include?(letter)
68
+ @result_builder.included
74
69
  else
75
- :gray
70
+ @result_builder.miss
76
71
  end
77
72
  end
78
73
  end
79
74
 
80
- colors
75
+ results
81
76
  end
82
77
  end
83
78
  end
data/lib/wordle/legend.rb CHANGED
@@ -2,29 +2,41 @@
2
2
 
3
3
  module Wordle
4
4
  class Legend
5
- def self.print
6
- new.print
5
+ def self.print(*args)
6
+ new(*args).print
7
+ end
8
+
9
+ def initialize(result_builder = ResultBuilder.new)
10
+ @result_builder = result_builder
7
11
  end
8
12
 
9
13
  def print
10
- puts green_example
11
- puts yellow_example
12
- puts gray_example
14
+ puts match_example
15
+ puts included_example
16
+ puts miss_example
13
17
  puts "\nRestart and add -i flag to target a specific word by hash, for example:"
14
18
  puts "$ wordle -i ed541a\n\n"
15
19
  end
16
20
 
17
21
  private
18
22
 
19
- def green_example
20
- "#{"w".green}eary - The letter w is in the word and in the correct spot."
23
+ def match_color
24
+ @result_builder.match_text_color
25
+ end
26
+
27
+ def included_color
28
+ @result_builder.included_text_color
29
+ end
30
+
31
+ def match_example
32
+ "#{"w".send(match_color)}eary - The letter w is in the word and in the correct spot."
21
33
  end
22
34
 
23
- def yellow_example
24
- "p#{"i".yellow}lls - The letter i is in the word but in the wrong spot."
35
+ def included_example
36
+ "p#{"i".send(included_color)}lls - The letter i is in the word but in the wrong spot."
25
37
  end
26
38
 
27
- def gray_example
39
+ def miss_example
28
40
  "vag#{"u".gray}e - The letter u is not in the word in any spot."
29
41
  end
30
42
  end
@@ -15,6 +15,10 @@ module Wordle
15
15
  opts.on("-d", "--difficult", "Hard mode. Any revealed hints must be used in subsequent guesses.") do |d|
16
16
  options[:difficult] = d
17
17
  end
18
+
19
+ opts.on("-c", "--contrast", "High contrast mode. Matched letters will be orange. Included letters will be blue.") do |c|
20
+ options[:contrast] = c
21
+ end
18
22
  end
19
23
 
20
24
  begin
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wordle
4
+ class ResultBuilder
5
+ MATCH = :match
6
+ INCLUDED = :included
7
+ MISS = :miss
8
+
9
+ DEFAULT_OPTIONS = {
10
+ MATCH => {text: :green, square: "🟩"},
11
+ INCLUDED => {text: :yellow, square: "🟨"},
12
+ MISS => {text: :gray, square: "⬛️"}
13
+ }.freeze
14
+
15
+ CONTRAST_OPTIONS = {
16
+ MATCH => {text: :orange, square: "🟧"},
17
+ INCLUDED => {text: :blue, square: "🟦"},
18
+ MISS => {text: :gray, square: "⬛️"}
19
+ }.freeze
20
+
21
+ def initialize(contrast = false)
22
+ @contrast = contrast
23
+ end
24
+
25
+ def match?(result)
26
+ result == MATCH
27
+ end
28
+
29
+ def included?(result)
30
+ result == INCLUDED
31
+ end
32
+
33
+ def match
34
+ MATCH
35
+ end
36
+
37
+ def included
38
+ INCLUDED
39
+ end
40
+
41
+ def miss
42
+ MISS
43
+ end
44
+
45
+ def match_text_color
46
+ options[match][:text]
47
+ end
48
+
49
+ def included_text_color
50
+ options[included][:text]
51
+ end
52
+
53
+ def text_color(result)
54
+ options[result][:text]
55
+ end
56
+
57
+ def square(result)
58
+ options[result][:square]
59
+ end
60
+
61
+ private
62
+
63
+ def options
64
+ return DEFAULT_OPTIONS if !@contrast
65
+ @_options ||= CONTRAST_OPTIONS
66
+ end
67
+ end
68
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wordle
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/wordle.rb CHANGED
@@ -4,14 +4,15 @@ require "digest"
4
4
  require "optparse"
5
5
  require_relative "integer"
6
6
  require_relative "string"
7
- require_relative "wordle/version"
8
- require_relative "wordle/options"
9
- require_relative "wordle/source"
10
- require_relative "wordle/list"
11
- require_relative "wordle/guess_validator"
7
+ require_relative "wordle/game"
12
8
  require_relative "wordle/guess_analyzer"
9
+ require_relative "wordle/guess_validator"
13
10
  require_relative "wordle/legend"
14
- require_relative "wordle/game"
11
+ require_relative "wordle/list"
12
+ require_relative "wordle/options"
13
+ require_relative "wordle/result_builder"
14
+ require_relative "wordle/source"
15
+ require_relative "wordle/version"
15
16
 
16
17
  module Wordle
17
18
  class Error < StandardError; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Thom
@@ -54,6 +54,7 @@ files:
54
54
  - lib/wordle/legend.rb
55
55
  - lib/wordle/list.rb
56
56
  - lib/wordle/options.rb
57
+ - lib/wordle/result_builder.rb
57
58
  - lib/wordle/source.rb
58
59
  - lib/wordle/version.rb
59
60
  - wordle.gemspec
@@ -80,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  - !ruby/object:Gem::Version
81
82
  version: '0'
82
83
  requirements: []
83
- rubygems_version: 3.3.3
84
+ rubygems_version: 3.3.7
84
85
  signing_key:
85
86
  specification_version: 4
86
87
  summary: Wordle CLI in Ruby