boggle_solver 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/boggle_solver-0.0.2.gem +0 -0
- data/boggle_solver.gemspec +2 -2
- data/lib/boggle_solver/board.rb +21 -7
- data/lib/boggle_solver/options.rb +36 -1
- data/lib/boggle_solver/runner.rb +3 -2
- data/{boggle_solver-0.0.1.gem → pkg/boggle_solver-0.0.1.gem} +0 -0
- data/pkg/boggle_solver-0.0.2.gem +0 -0
- metadata +48 -14
Binary file
|
data/boggle_solver.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "boggle_solver"
|
3
3
|
s.summary = "Find all words in a letter matrix"
|
4
|
-
s.description =
|
4
|
+
s.description = File.read(File.join(File.dirname(__FILE__), 'README.markdown'))
|
5
5
|
s.requirements = "[ 'An installed dictionary (most Unix systems have one)']"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.3"
|
7
7
|
s.author = "Casey Robinson"
|
8
8
|
s.email = "kc@rampantmonkey.com"
|
9
9
|
s.homepage = "http://rampantmonkey.com"
|
data/lib/boggle_solver/board.rb
CHANGED
@@ -6,13 +6,18 @@ module BoggleSolver
|
|
6
6
|
class Board < AdjacencyMatrix
|
7
7
|
attr_reader :words
|
8
8
|
|
9
|
-
def initialize
|
9
|
+
def initialize(mode=:default)
|
10
10
|
super(25)
|
11
11
|
connect
|
12
12
|
@board = []
|
13
|
-
|
13
|
+
if mode == :random
|
14
|
+
@prng = Random.new
|
15
|
+
generate_random_board
|
16
|
+
else
|
17
|
+
generate_board
|
18
|
+
end
|
19
|
+
puts self
|
14
20
|
@words = []
|
15
|
-
generate_board
|
16
21
|
load_dictionary
|
17
22
|
end
|
18
23
|
|
@@ -32,10 +37,19 @@ module BoggleSolver
|
|
32
37
|
end
|
33
38
|
|
34
39
|
def generate_board
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
40
|
+
@board = ["a", "r", "t", "a", "c", "c", "e", "a", "r", "d", "f", "e", "w", "o", "o", "n", "p", "l", "m", "i", "c", "r", "u", "b", "l"]
|
41
|
+
calculate_board_hash
|
42
|
+
end
|
43
|
+
|
44
|
+
def generate_random_board
|
45
|
+
@board = Array.new(25)
|
46
|
+
@board.map!{|item| (65.+rand(25)).chr.downcase!}
|
47
|
+
calculate_board_hash
|
48
|
+
end
|
49
|
+
|
50
|
+
def calculate_board_hash
|
51
|
+
@board_hash = Hash.new(0)
|
52
|
+
@board.each {|letter| @board_hash[letter] += 1}
|
39
53
|
end
|
40
54
|
|
41
55
|
def load_dictionary
|
@@ -1,6 +1,41 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
|
3
|
-
module
|
3
|
+
module BoggleSolver
|
4
4
|
class Options
|
5
5
|
|
6
6
|
DEFAULT_DICTIONARY = "/usr/share/dict/words"
|
7
|
+
|
8
|
+
attr_reader :dictionary, :mode
|
9
|
+
|
10
|
+
def initialize(argv)
|
11
|
+
@dictionary = DEFAULT_DICTIONARY
|
12
|
+
@mode = :default
|
13
|
+
parse(argv)
|
14
|
+
@input = argv
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse(argv)
|
18
|
+
OptionParser.new do |opts|
|
19
|
+
opts.banner = "Usage: boggle_solver [ options ] "
|
20
|
+
opts.on("-d", "--dict path", String, "Path to dictionary") do |dict|
|
21
|
+
@dictionary = dict
|
22
|
+
end
|
23
|
+
opts.on("-h", "--help", "Show this message") do
|
24
|
+
puts opts
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
opts.on("-r", "--random", "Use a random board") do
|
28
|
+
@mode = :random
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
argv = ["-h"] if argv.empty?
|
33
|
+
opts.parse!(argv)
|
34
|
+
rescue OptionParser::ParseError => e
|
35
|
+
STDERR.puts e.message, "\n", opts
|
36
|
+
exit(-1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/boggle_solver/runner.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
require_relative 'board'
|
2
|
+
require_relative 'options'
|
2
3
|
|
3
4
|
module BoggleSolver
|
4
5
|
|
5
6
|
class Runner
|
6
7
|
def initialize(argv)
|
7
|
-
|
8
|
+
@options = Options.new(argv)
|
8
9
|
end
|
9
10
|
|
10
11
|
def run
|
11
|
-
board = Board.new
|
12
|
+
board = Board.new(@options.mode)
|
12
13
|
board.find_words
|
13
14
|
p board.words
|
14
15
|
end
|
File without changes
|
Binary file
|
metadata
CHANGED
@@ -1,58 +1,92 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boggle_solver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Casey Robinson
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-15 00:00:00.
|
12
|
+
date: 2012-05-15 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: ! "Ruby program that employs graph theory to solve a word matrix puzzle\
|
15
|
+
\ (Boggle).\n\n# Introduction\nBoggle Master consists of a 5x5 grid of letters.\
|
16
|
+
\ The goal of the game is to make as many words as possible from this grid by connecting\
|
17
|
+
\ neighboring letters. To generate a random puzzle the game uses 25 dice with letters\
|
18
|
+
\ on each side. The dice are shaken and each fall into a slot in the grid.\n\n#\
|
19
|
+
\ Example Grid\n\nBelow is an example grid. One possible word in this graph is `wear`.\
|
20
|
+
\ Arrows are added for convenience.\n\n J O X T Y\n\n A C D\
|
21
|
+
\ F P\n\n Y K B E O\n\n A M G P W\n \
|
22
|
+
\ |\n D S R<--A<--E\n\nThe goal of this project is to find all possible\
|
23
|
+
\ words. Mostly to serve as a benchmark with which to compare my performance.\n\n\
|
24
|
+
\n# Coordinate System\nBelow are the indicies used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 0 0 0 1 1\
|
38
|
+
\ 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 1 1 0 0 0\n 0 0 0 0\
|
39
|
+
\ 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 1 1 1 0 0\n 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0\
|
40
|
+
\ 1 0 1 0 0 1 1 1 0\n 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 1 1 1\n \
|
41
|
+
\ 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 1\n 0 0 0 0 0 0 0 0 0 0 0 0\
|
42
|
+
\ 0 0 0 1 1 0 0 0 0 1 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0\
|
43
|
+
\ 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0\n 0 0 0 0 0 0 0 0\
|
44
|
+
\ 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1\
|
45
|
+
\ 0 0 0 1 0\n"
|
15
46
|
email: kc@rampantmonkey.com
|
16
47
|
executables:
|
17
48
|
- boggle_solver
|
18
49
|
extensions: []
|
19
50
|
extra_rdoc_files: []
|
20
51
|
files:
|
21
|
-
-
|
22
|
-
- boggle_solver-0.0.1.gem
|
52
|
+
- boggle_solver-0.0.2.gem
|
23
53
|
- boggle_solver.gemspec
|
54
|
+
- README.markdown
|
55
|
+
- bin/boggle_solver
|
24
56
|
- lib/boggle_solver/adjacency_matrix.rb
|
25
57
|
- lib/boggle_solver/board.rb
|
26
58
|
- lib/boggle_solver/options.rb
|
27
59
|
- lib/boggle_solver/runner.rb
|
28
|
-
-
|
60
|
+
- pkg/boggle_solver-0.0.1.gem
|
61
|
+
- pkg/boggle_solver-0.0.2.gem
|
29
62
|
- test/test_adjacency_matrix.rb
|
30
63
|
- test/test_board.rb
|
31
64
|
homepage: http://rampantmonkey.com
|
32
65
|
licenses: []
|
33
|
-
post_install_message:
|
66
|
+
post_install_message:
|
34
67
|
rdoc_options: []
|
35
68
|
require_paths:
|
36
69
|
- lib
|
37
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
71
|
requirements:
|
40
72
|
- - ! '>='
|
41
73
|
- !ruby/object:Gem::Version
|
42
74
|
version: '1.9'
|
43
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
75
|
none: false
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
77
|
requirements:
|
46
78
|
- - ! '>='
|
47
79
|
- !ruby/object:Gem::Version
|
48
80
|
version: '0'
|
81
|
+
none: false
|
49
82
|
requirements:
|
50
83
|
- ! '[ ''An installed dictionary (most Unix systems have one)'']'
|
51
|
-
rubyforge_project:
|
52
|
-
rubygems_version: 1.8.
|
53
|
-
signing_key:
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.15
|
86
|
+
signing_key:
|
54
87
|
specification_version: 3
|
55
88
|
summary: Find all words in a letter matrix
|
56
89
|
test_files:
|
57
90
|
- test/test_adjacency_matrix.rb
|
58
91
|
- test/test_board.rb
|
92
|
+
...
|