nonograms 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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|
@@ -50,11 +50,7 @@ class Nonograms
50
50
 
51
51
  # get the matrix with cells values zero
52
52
  def create_matrix
53
- result = []
54
- @height.times do |index|
55
- result << [0]*@width
56
- end
57
- result
53
+ (0...@height).to_a.map {|element| [0]*@width}
58
54
  end
59
55
  end
60
56
  end
@@ -1,3 +1,3 @@
1
1
  class Nonograms
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -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-10"
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($\)
@@ -2,17 +2,32 @@ require 'nonograms'
2
2
 
3
3
  describe Nonograms do
4
4
 
5
- before(:each) do
6
- vertical = [[1], [2, 1], [1], [], [1, 1]]
7
- horizontal = [[1], [2, 1], [1], [1, 1]]
8
- @nonograms = Nonograms.new(horizontal, vertical)
9
- end
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
- it "should properly solve the nonograms" do
12
- @nonograms.solve.should include("01000"+"01101"+"10000"+"01001")
16
+ it "should properly entered data" do
17
+ @nonograms.properly_data_entered?.should be_true
18
+ end
13
19
  end
14
20
 
15
- it "should properly entered data" do
16
- @nonograms.properly_data_entered?.should be_true
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.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-10 00:00:00.000000000 Z
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec