wordle 0.2.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: 5914b5021b2c898710efdb9910e7d4e0f4763ee6f6948748cb8eb333dbc734da
4
- data.tar.gz: 956fee31223a324a258d7e2ea42dda4596950f4395ed2a3a6811267509268919
3
+ metadata.gz: 37a2b0b303c14b7f71edbfd175f86a25614a3fc103ba6d1870c02432d2d6010f
4
+ data.tar.gz: 336637bbb33eecf7647cc166aa98f0cd3e75e354346a9ac16a3f083a32c24412
5
5
  SHA512:
6
- metadata.gz: 407e1b1c701c175929a345e810400a833508804c708d9c59c75336985c382d791513241e56fb7f4e4d776a53e9b00babe3f3a113d662ccaeef0259c9832bd66d
7
- data.tar.gz: 0fe026d67b821cdabdcdb93427a8768149ac20d40bdd732007dd787b713af22f7e67bbb8782d65728b4e5b5079e271fcb3ce62c473bf04d131b0a1edd133112e
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,4 +1,25 @@
1
- ## [Unreleased]
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
+
7
+ ## [0.4.0] - 2022-01-14
8
+
9
+ - Fixes bug where too many letters would get marked as yellow. Resolves
10
+ [https://github.com/JonathanWThom/wordle/issues/3](https://github.com/JonathanWThom/wordle/issues/3).
11
+
12
+ ## [0.3.0] - 2022-01-10
13
+
14
+ - Adds a better world list. From the Wordle source itself : )
15
+
16
+ ## [0.2.1] - 2022-01-10
17
+
18
+ - Adds legend for colors
19
+
20
+ ## [0.2.0] - 2022-01-09
21
+
22
+ - Actually tells you what the word was if you don't win!
2
23
 
3
24
  ## [0.1.1] - 2022-01-09
4
25
 
data/Gemfile.lock CHANGED
@@ -1,19 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wordle (0.2.0)
4
+ wordle (0.5.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)
11
+ irb (>= 1.3.6)
12
+ reline (>= 0.2.7)
10
13
  diff-lcs (1.5.0)
14
+ io-console (0.5.11)
15
+ irb (1.4.1)
16
+ reline (>= 0.3.0)
11
17
  parallel (1.21.0)
12
18
  parser (3.1.0.0)
13
19
  ast (~> 2.4.1)
14
20
  rainbow (3.0.0)
15
21
  rake (13.0.6)
16
22
  regexp_parser (2.2.0)
23
+ reline (0.3.1)
24
+ io-console (~> 0.5)
17
25
  rexml (3.2.5)
18
26
  rspec (3.10.0)
19
27
  rspec-core (~> 3.10.0)
@@ -53,6 +61,7 @@ PLATFORMS
53
61
  x86_64-linux
54
62
 
55
63
  DEPENDENCIES
64
+ debug (>= 1.0.0)
56
65
  rake (~> 13.0)
57
66
  rspec (~> 3.0)
58
67
  standard (~> 1.3)
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="304" alt="Screen Shot 2022-01-09 at 3 06 39 PM" src="https://user-images.githubusercontent.com/22665228/148704931-dc74bc7a-8987-4ecd-a83d-678e647d20b5.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.
@@ -20,7 +27,11 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
20
27
 
21
28
  ## Contributing
22
29
 
23
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wordle. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/wordle/blob/main/CODE_OF_CONDUCT.md).
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/JonathanWThom/wordle. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/JonathanWThom/wordle/blob/main/CODE_OF_CONDUCT.md).
31
+
32
+ ## Acknowledgements
33
+
34
+ I cribbed my word list from the Wordle site itself. I have no association with the site or its creator, I'm just a fan!
24
35
 
25
36
  ## License
26
37
 
@@ -28,4 +39,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
28
39
 
29
40
  ## Code of Conduct
30
41
 
31
- Everyone interacting in the Wordle project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/wordle/blob/main/CODE_OF_CONDUCT.md).
42
+ Everyone interacting in the Wordle project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/JonathanWThom/wordle/blob/main/CODE_OF_CONDUCT.md).
data/lib/wordle/game.rb CHANGED
@@ -8,19 +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
 
18
+ Legend.print
21
19
  puts "Guess a 5 letter word: "
20
+ guesses = []
22
21
 
23
- while attempts < 6 && !winner
22
+ while guesses.length < 6 && !winner
24
23
  guess = gets.chomp
25
24
 
26
25
  validator = GuessValidator.new(guess, @list)
@@ -31,27 +30,52 @@ module Wordle
31
30
 
32
31
  analyzer = GuessAnalyzer.new(@target_word, guess)
33
32
  puts analyzer.colors
33
+ guesses << analyzer.squares
34
34
 
35
35
  if analyzer.match?
36
36
  winner = true
37
37
  break
38
38
  end
39
-
40
- attempts += 1
41
39
  end
42
40
 
41
+ hash = Digest::SHA2.hexdigest(@target_word)[..5]
43
42
  if winner
44
- puts "Winner!"
43
+ puts "\nWordle Gem #{hash} #{guesses.length}/6\n\n"
45
44
  else
46
- puts "Word was: #{@target_word}"
47
- puts "Better luck next time!"
45
+ puts "\nWord was: #{@target_word}\n"
46
+ puts "\nWordle Gem #{hash} X/6*\n\n"
48
47
  end
48
+
49
+ puts guesses
49
50
  end
50
51
 
51
52
  private
52
53
 
53
54
  def generate_word
54
- @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
55
79
  end
56
80
  end
57
81
  end
@@ -14,21 +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
- colored_letters += if letter == target_letters[i]
23
- letter.green
24
- elsif target_letters.include?(letter)
25
- letter.yellow
26
- else
27
- letter.gray
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
28
50
  end
29
- end
30
51
 
31
- colored_letters
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
59
+ end
60
+ end
61
+
62
+ colors
63
+ end
32
64
  end
33
65
  end
34
66
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wordle
4
+ class Legend
5
+ def self.print
6
+ new.print
7
+ end
8
+
9
+ def print
10
+ puts green_example
11
+ puts yellow_example
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"
15
+ end
16
+
17
+ private
18
+
19
+ def green_example
20
+ "#{"w".green}eary - The letter w is in the word and in the correct spot."
21
+ end
22
+
23
+ def yellow_example
24
+ "p#{"i".yellow}lls - The letter i is in the word but in the wrong spot."
25
+ end
26
+
27
+ def gray_example
28
+ "vag#{"u".gray}e - The letter u is not in the word in any spot."
29
+ end
30
+ end
31
+ end
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
@@ -17,10 +23,7 @@ module Wordle
17
23
  private
18
24
 
19
25
  def list
20
- # fall back to api if this fails?
21
- @_list ||= File.readlines("/usr/share/dict/words").select do |word|
22
- word.strip.length == @length
23
- end.map { |w| w.downcase.strip } # sanitize class to standarize this?
26
+ @_list ||= Wordle::SOURCE
24
27
  end
25
28
  end
26
29
  end