word_searcher 1.01 → 1.02

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: 72bcf8318fafd86721a89aa88cc4e1416491566dd6c77674309fc8b3b99d427f
4
- data.tar.gz: 5b1626a2e597725c17921619ef23ae503a04f1f455bb7082823c81934c6a341e
3
+ metadata.gz: 5c63215a765c3030d4d38c9411524c4b7be44f35de82106ba4b93f6c693bfa69
4
+ data.tar.gz: 334e725678b086810571fca347ef43e8845a3a9d7f6795afcad4c510c403ac8d
5
5
  SHA512:
6
- metadata.gz: 545d726b3e61ad958aa31dfc60c5bcd9a7b45980d048a8c7376a1666499e9f75442f722fd988185e52d9e4624dea5eca39b960db0cb6ce64c0de4188d6020ed8
7
- data.tar.gz: 0120f6f93d41741841abda4bb0b2b6b42641ec6dc3f92a6982d98ee3d56f772fb03519de27772e6712b64a671ae4bbed58679ac5a20b9a8a388a211a4cea6031
6
+ metadata.gz: 731db95982679d584d6fba5b6bf65de040d55a37babf408a7fb7ec1a732c870f6b0172692d57f4be2daf406c8f6bb1ff5c69a88732c646d894ebd7099067793a
7
+ data.tar.gz: 96e26d23ca1778aba3e18412ecf2c5f66be7fe5b3c180e33d49ca6a643e4b1aa4b9f3f2d7c734d3529814ef446c23d147f174f876b237384b431083b6b592b56
data/README.md CHANGED
@@ -4,8 +4,7 @@
4
4
  [![MIT License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
6
  #### Creates and solves word search game.
7
-
8
- Note: Currently being moved from local environment to this gem. Will be completed by 7/10/18
7
+ WordSearcher generates a new word search puzzle with your input word, then tries to solve the puzzle. It is not programmed to win every game. It simply compares each letter of the word with all those available on the board, then randomly selects one. Then, if looks to see if the next letter of the word is joining the prior, and so forth. It plays more like a human, rather than a computer, so make the game more fun. Each time you play, notice that the board changes each time, even for the same input word.
9
8
 
10
9
  ## Installation
11
10
 
@@ -25,7 +24,34 @@ Or install it yourself as:
25
24
 
26
25
  ## Usage
27
26
 
28
- Note: Currently being moved from local environment to this gem. Will be completed by 7/10/18
27
+ 1) Add your word to a hash with `:word` symbol key, then pass the arguments to `WordSearcher.search(args)` like the example below. If you don't pass any args, and just run `WordSearcher.search` it will return sample data for testing.
28
+
29
+ ```
30
+ result = WordSearcher.search(word: 'austin')
31
+ ```
32
+
33
+ 2) The returned data will be in hash format like below:
34
+
35
+ ```
36
+ {
37
+ :word=>"austin",
38
+ :found=>["a", "u", "s", "t", "i", "n"],
39
+ :remaining=>[],
40
+ :win=>true,
41
+ :puzzle=>
42
+ [
43
+ ["l", "a", "w", "r", "h", "z", "b"],
44
+ ["i", "p", "m", "b", "c", "j", "l"],
45
+ ["k", "j", "h", "c", "t", "a", "y"],
46
+ ["a", "u", "s", "t", "i", "n", "t"],
47
+ ["d", "s", "o", "v", "f", "x", "h"],
48
+ ["z", "d", "u", "a", "e", "k", "n"],
49
+ ["q", "y", "l", "c", "s", "d", "u"],
50
+ ["k", "z", "r", "m", "x", "g", "d"]
51
+ ]
52
+ }
53
+ ```
54
+
29
55
 
30
56
  ## Development
31
57
 
data/Rakefile CHANGED
@@ -17,22 +17,16 @@ task :console do
17
17
  require "active_support/all"
18
18
  ARGV.clear
19
19
 
20
- scraped_links = run_word_searcher
21
- # binding.pry
20
+ result = run_word_searcher
21
+ binding.pry
22
22
 
23
23
  IRB.start
24
24
  end
25
25
 
26
26
 
27
27
  def run_word_searcher
28
- binding.pry
29
- searched = WordSearcher::Searcher.new
30
- res = searched.start
31
- binding.pry
32
-
33
- # scraper = LinkScraper::Scrape.new({text_criteria: text_criteria, path_criteria: path_criteria})
34
- # scraped_links = scraper.start('https://en.wikipedia.org/wiki/Austin%2C_Texas')
35
- # binding.pry
28
+ word = 'austin'
29
+ result = WordSearcher.search(word: word)
36
30
 
37
31
  # scraper = LinkScraper::Scrape.new(WebsCriteria.all_scrub_web_criteria)
38
32
  end
@@ -0,0 +1,135 @@
1
+
2
+ module WordSearcher
3
+ class Solver
4
+
5
+ def initialize
6
+ @word = []
7
+ @puzzle = []
8
+ @word_chars = []
9
+ @found = []
10
+ @first_letter = nil
11
+ @coords = []
12
+ end
13
+
14
+ # AlgoService.new.search
15
+ def search(args = {})
16
+ @word = args.fetch(:word, nil)
17
+ @word = generate_word if !@word.present?
18
+ @puzzle = args.fetch(:puzzle, nil)
19
+ @puzzle = generate_puzzle if !@puzzle.present?
20
+
21
+ @word_chars = @word.chars
22
+ @found = []
23
+ @first_letter = @word[0]
24
+ @coords = []
25
+ find_coordinates
26
+ iterate_coords
27
+ score_hsh = check_score
28
+ end
29
+
30
+ def check_score
31
+ remaining = @word_chars - @found
32
+ found = @found & @word_chars
33
+ remaining.any? ? win = false : win = true
34
+ score_hsh = {word: @word, found: found, remaining: remaining, win: win, puzzle: @puzzle}
35
+ end
36
+
37
+ def find_coordinates
38
+ @puzzle.each_with_index do |row, ri|
39
+ find_col_index(row, ri)
40
+ end
41
+ end
42
+
43
+ def find_col_index(row, ri)
44
+ if row&.include?(@first_letter)
45
+ ci = row.index(@first_letter)
46
+ col = @puzzle.map { |row| row[ci] }
47
+ coord_hsh = { row: row, col: col, ri: ri, ci: ci }
48
+ @coords << coord_hsh
49
+ end
50
+ end
51
+
52
+ def iterate_coords
53
+ if @coords.any?
54
+ @word_chars[0..-1].each do |letter|
55
+ @coords.each do |coord|
56
+ neighbors = get_neighbors(coord)
57
+ neighbors = neighbors.values.flatten.uniq
58
+ @found << letter if neighbors.include?(letter)
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def get_neighbors(coord)
65
+ row_range = get_range(coord[:ri]).to_a
66
+ col_range = get_range(coord[:ci]).to_a
67
+ start = col_range.first
68
+ stop = col_range.last
69
+
70
+ neighbors = { top: @puzzle[row_range.first][start..stop],
71
+ mid: @puzzle[coord[:ri]][start..stop],
72
+ bot: @puzzle[row_range.last][start..stop]
73
+ }
74
+ end
75
+
76
+ def get_range(index)
77
+ row_range = (0...7).to_a
78
+ indexes = (index-1..index+1).to_a.map do |new_index|
79
+ row_range.include?(new_index) ? new_index : index
80
+ end
81
+ end
82
+
83
+ # def self.make_puzzle
84
+ # binding.pry
85
+ # puzzles = []
86
+ #
87
+ # puzzles << { word: 'wolves',
88
+ # puzzle: [["a", "w", "o", "l", "v", "e", "s"],
89
+ # ["s", "o", "a", "w", "a", "h", "p"],
90
+ # ["i", "t", "c", "k", "e", "t", "n"],
91
+ # ["o", "t", "s", "d", "h", "o", "h"],
92
+ # ["s", "e", "h", "g", "s", "t", "a"],
93
+ # ["u", "r", "p", "i", "w", "e", "u"],
94
+ # ["z", "s", "b", "n", "u", "i", "r"]] }
95
+ #
96
+ # puzzles << { word: 'wolves',
97
+ # puzzle: [["a", "w", "o", "l", "v", "e", "s"],
98
+ # ["s", "o", "a", "w", "a", "h", "p"],
99
+ # ["i", "t", "c", "k", "e", "t", "n"],
100
+ # ["o", "t", "s", "d", "h", "o", "h"],
101
+ # ["s", "e", "h", "g", "s", "t", "a"],
102
+ # ["u", "r", "p", "i", "w", "e", "u"],
103
+ # ["z", "s", "b", "n", "u", "i", "r"]] }
104
+ #
105
+ # puzzle = puzzles.sample
106
+ # end
107
+
108
+
109
+ def generate_puzzle
110
+ word = @word
111
+ word = word.chars
112
+ while word.length < 7
113
+ alph = ('a'..'z').to_a.sample
114
+ word.length.odd? ? pos = 0 : pos = -1
115
+ word.insert(pos,alph)
116
+ end
117
+
118
+ puzzle = (0..7).map { ('a'..'z').to_a.shuffle[0,7] }
119
+ n = rand(0..7)
120
+ puzzle[n] = word
121
+ @puzzle = puzzle
122
+ end
123
+
124
+
125
+ def generate_word
126
+ # words = %w(texas austin dallas houston cowboy)
127
+ # word = words.shuffle.sample
128
+ word = 'texas'
129
+ end
130
+
131
+
132
+
133
+
134
+ end
135
+ end
@@ -1,3 +1,3 @@
1
1
  module WordSearcher
2
- VERSION = "1.01"
2
+ VERSION = "1.02"
3
3
  end
data/lib/word_searcher.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  require "word_searcher/version"
2
2
 
3
- require "word_searcher/searcher"
3
+ require "word_searcher/solver"
4
4
  # require 'mechanizer'
5
5
  # require 'scrub_db'
6
6
  require 'pry'
7
7
 
8
8
  module WordSearcher
9
- # Your code goes here...
9
+
10
+ def self.search(args={})
11
+ results = self::Solver.new.search(args)
12
+ end
13
+
14
+
10
15
  end
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Adam Booth"]
10
10
  spec.email = ["4rlm@protonmail.ch"]
11
11
 
12
- spec.summary = %q{Creates and solves word search game}
13
- spec.description = %q{Creates and solves word search game.}
12
+ spec.summary = %q{WordSearcher generates a new word search puzzle with your input word, then tries to solve the puzzle}
13
+ spec.description = %q{WordSearcher generates a new word search puzzle with your input word, then tries to solve the puzzle. It is not programmed to win every game. It simply compares each letter of the word with all those available on the board, then randomly selects one. Then, if looks to see if the next letter of the word is joining the prior, and so forth. It plays more like a human, rather than a computer, so make the game more fun. Each time you play, notice that the board changes each time, even for the same input word.}
14
14
 
15
15
  spec.homepage = 'https://github.com/4rlm/word_searcher'
16
16
  spec.license = "MIT"
@@ -32,11 +32,11 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.required_ruby_version = '~> 2.5.1'
34
34
  spec.add_dependency 'activesupport', '~> 5.2'
35
- spec.add_dependency 'crm_formatter', '~> 2.64'
35
+ spec.add_dependency 'crm_formatter', '~> 2.65'
36
36
  spec.add_dependency 'mechanizer', '~> 1.12'
37
37
  spec.add_dependency 'scrub_db', '~> 2.23'
38
38
  spec.add_dependency 'url_verifier', '~> 2.12'
39
- spec.add_dependency 'utf8_sanitizer', '~> 2.16'
39
+ # spec.add_dependency 'utf8_sanitizer', '~> 2.16'
40
40
 
41
41
  # spec.add_dependency "activesupport-inflector", ['~> 0.1.0']
42
42
  spec.add_development_dependency 'bundler', '~> 1.16', '>= 1.16.2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: word_searcher
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.01'
4
+ version: '1.02'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Booth
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-05 00:00:00.000000000 Z
11
+ date: 2018-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.64'
33
+ version: '2.65'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.64'
40
+ version: '2.65'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mechanizer
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.12'
83
- - !ruby/object:Gem::Dependency
84
- name: utf8_sanitizer
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.16'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '2.16'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: bundler
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -162,7 +148,13 @@ dependencies:
162
148
  - - "~>"
163
149
  - !ruby/object:Gem::Version
164
150
  version: '3.7'
165
- description: Creates and solves word search game.
151
+ description: WordSearcher generates a new word search puzzle with your input word,
152
+ then tries to solve the puzzle. It is not programmed to win every game. It simply
153
+ compares each letter of the word with all those available on the board, then randomly
154
+ selects one. Then, if looks to see if the next letter of the word is joining the
155
+ prior, and so forth. It plays more like a human, rather than a computer, so make
156
+ the game more fun. Each time you play, notice that the board changes each time,
157
+ even for the same input word.
166
158
  email:
167
159
  - 4rlm@protonmail.ch
168
160
  executables: []
@@ -180,7 +172,7 @@ files:
180
172
  - bin/console
181
173
  - bin/setup
182
174
  - lib/word_searcher.rb
183
- - lib/word_searcher/searcher.rb
175
+ - lib/word_searcher/solver.rb
184
176
  - lib/word_searcher/version.rb
185
177
  - word_searcher.gemspec
186
178
  homepage: https://github.com/4rlm/word_searcher
@@ -207,5 +199,6 @@ rubyforge_project:
207
199
  rubygems_version: 2.7.6
208
200
  signing_key:
209
201
  specification_version: 4
210
- summary: Creates and solves word search game
202
+ summary: WordSearcher generates a new word search puzzle with your input word, then
203
+ tries to solve the puzzle
211
204
  test_files: []
@@ -1,17 +0,0 @@
1
-
2
- module WordSearcher
3
- class Searcher
4
-
5
- def initialize
6
- binding.pry
7
- end
8
-
9
- def start
10
- binding.pry
11
- "testing setup"
12
- end
13
-
14
-
15
-
16
- end
17
- end