automaze 0.0.2 → 0.0.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{automaze}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Toshiyuki Hirooka"]
@@ -1,6 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Boutaoshi
4
+ def init_panels
5
+ each_panels do |panel, x, y|
6
+ panel.set_kind(:floor)
7
+ panel.set_kind(:wall) if post?(x,y)
8
+ end
9
+ end
10
+
4
11
  def generate
5
12
  init_panels
6
13
 
@@ -17,13 +24,6 @@ module Boutaoshi
17
24
  end
18
25
  end
19
26
 
20
- def init_panels
21
- each_panels do |panel, x, y|
22
- panel.set_kind(:floor)
23
- panel.set_kind(:wall) if post?(x,y)
24
- end
25
- end
26
-
27
27
  def post?(x,y)
28
28
  ( x % 2 ) == 1 && ( y % 2 ) == 1
29
29
  end
@@ -8,6 +8,7 @@ module DugTunnels
8
8
  end
9
9
 
10
10
  def generate
11
+ @dug_count = 0
11
12
  init_panels
12
13
 
13
14
  # start point
@@ -55,17 +56,13 @@ module DugTunnels
55
56
  end
56
57
 
57
58
  def dug_all?
58
- each_panels do |panel, x, y|
59
- if ( x % 2 ) == 0 && ( y % 2 ) == 0
60
- return false if panel.wall?
61
- end
62
- end
63
- return true
59
+ @dug_count >= (size_x+2)* (size_y+2) / 4 - 1
64
60
  end
65
61
 
66
62
  def dig(x, y, dir)
67
63
  xy = next_xy(x, y, dir)
68
64
  panels(*xy).set_kind(:floor)
65
+ @dug_count += 1
69
66
 
70
67
  diff = [xy[0] - x, xy[1] - y]
71
68
  if diff[0] == 0
@@ -42,7 +42,7 @@ module Automaze
42
42
 
43
43
  @size_x = options.delete(:size_x) || 30
44
44
  @size_y = options.delete(:size_y) || 20
45
- self.class.include_algorithm options.delete(:algorithm) || DEFAULT_ALGORITHM
45
+ self.class.include_algorithm(options.delete(:algorithm) || DEFAULT_ALGORITHM)
46
46
  self.generate # included algorithm
47
47
  end
48
48
  attr_reader :size_x
@@ -110,18 +110,15 @@ module Automaze
110
110
  end
111
111
 
112
112
  def to_s
113
- str = ""
114
- (-1..@size_y+1).each {|y|
115
- (-1..@size_x+1).each {|x|
113
+ (-1..@size_y+1).map {|y|
114
+ (-1..@size_x+1).map {|x|
116
115
  if panels(x,y).wall?
117
- str += "XX"
116
+ "XX"
118
117
  else
119
- str += " "
118
+ " "
120
119
  end
121
- }
122
- str += "\n"
123
- }
124
- return str
120
+ }.join + "\n"
121
+ }.join
125
122
  end
126
123
  end
127
124
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Toshiyuki Hirooka