nonograms 0.2.2 → 0.2.3
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.
- data/lib/nonograms.rb +5 -0
- data/lib/nonograms/logic.rb +10 -0
- data/lib/nonograms/matrix.rb +1 -5
- data/lib/nonograms/version.rb +1 -1
- data/nonograms.gemspec +1 -1
- data/spec/nonograms_spec.rb +24 -9
- metadata +2 -2
data/lib/nonograms.rb
CHANGED
@@ -19,7 +19,11 @@ class Nonograms
|
|
19
19
|
# solve the nonograms
|
20
20
|
def solve
|
21
21
|
return @results unless @results.empty?
|
22
|
+
|
23
|
+
run_recursion
|
24
|
+
@logic.matrix.set(0, 0, 1)
|
22
25
|
run_recursion
|
26
|
+
|
23
27
|
@results
|
24
28
|
end
|
25
29
|
|
@@ -48,6 +52,7 @@ private
|
|
48
52
|
true
|
49
53
|
end
|
50
54
|
|
55
|
+
# set next cell of matrix on "value"
|
51
56
|
def next_cell_set(value, row, column)
|
52
57
|
new_row = (row*@amount_column + column + 1) / @amount_column
|
53
58
|
new_column = (row*@amount_column + column + 1) % @amount_column
|
data/lib/nonograms/logic.rb
CHANGED
@@ -17,10 +17,12 @@ class Nonograms
|
|
17
17
|
@matrix
|
18
18
|
end
|
19
19
|
|
20
|
+
# the vertical and the horizontal vectors have acceptable values
|
20
21
|
def cross_acceptable?(row, column)
|
21
22
|
vertical_acceptable?(row, column) and horizontal_acceptable?(row, column)
|
22
23
|
end
|
23
24
|
|
25
|
+
# the vertical vector have acceptable values
|
24
26
|
def vertical_acceptable?(row, column)
|
25
27
|
unless row == @amount_row-1
|
26
28
|
vector_acceptable?( @vertical[column], @matrix.count_vertical(column) )
|
@@ -29,6 +31,7 @@ class Nonograms
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
34
|
+
# the horizontal vector have acceptable values
|
32
35
|
def horizontal_acceptable?(row, column)
|
33
36
|
unless column == @amount_column-1
|
34
37
|
vector_acceptable?( @horizontal[row], @matrix.count_horizontal(row) )
|
@@ -37,6 +40,13 @@ class Nonograms
|
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
43
|
+
# the vector have acceptable values
|
44
|
+
# * origin - vector base
|
45
|
+
# * piece - vector to verifi
|
46
|
+
# * return - true or false
|
47
|
+
# example:
|
48
|
+
# origin = [3, 2, 2]; piece = [3, 1]; return true
|
49
|
+
# origin = [3, 2, 2]; piece = [3, 3]; return false
|
40
50
|
def vector_acceptable?(origin, piece)
|
41
51
|
return false if piece.length > origin.length
|
42
52
|
piece.each_with_index do |value, index|
|
data/lib/nonograms/matrix.rb
CHANGED
data/lib/nonograms/version.rb
CHANGED
data/nonograms.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["raglub.ruby@gmail.com"]
|
7
7
|
gem.description = %q{solve the puzzle game nonograms.}
|
8
8
|
gem.summary = %q{Solve Nonograms.}
|
9
|
-
gem.date = "2012-07-
|
9
|
+
gem.date = "2012-07-13"
|
10
10
|
gem.homepage = "https://github.com/raglub/nonograms"
|
11
11
|
|
12
12
|
gem.files = `git ls-files`.split($\)
|
data/spec/nonograms_spec.rb
CHANGED
@@ -2,17 +2,32 @@ require 'nonograms'
|
|
2
2
|
|
3
3
|
describe Nonograms do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
context "when first cell is zero" do
|
6
|
+
before(:each) do
|
7
|
+
vertical = [[1], [2, 1], [1], [], [1, 1]]
|
8
|
+
horizontal = [[1], [2, 1], [1], [1, 1]]
|
9
|
+
@nonograms = Nonograms.new(horizontal, vertical)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should properly solve the nonograms" do
|
13
|
+
@nonograms.solve.should include("01000"+"01101"+"10000"+"01001")
|
14
|
+
end
|
10
15
|
|
11
|
-
|
12
|
-
|
16
|
+
it "should properly entered data" do
|
17
|
+
@nonograms.properly_data_entered?.should be_true
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
|
-
|
16
|
-
|
21
|
+
context "when first cell is one" do
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
vertical = [[3], [1], [2], [1, 1], [1, 1], [1]]
|
25
|
+
horizontal = [[1, 3], [1], [5], [1]]
|
26
|
+
@nonograms = Nonograms.new(horizontal, vertical)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should properly solve the nonograms" do
|
30
|
+
@nonograms.solve.should include("100111" + "100000" + "111110" + "001000")
|
31
|
+
end
|
17
32
|
end
|
18
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nonograms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|