automaze 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/automaze.gemspec +1 -1
- data/lib/algorithms/boutaoshi.rb +7 -7
- data/lib/algorithms/dug_tunnels.rb +3 -6
- data/lib/automaze.rb +7 -10
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/automaze.gemspec
CHANGED
data/lib/algorithms/boutaoshi.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/automaze.rb
CHANGED
@@ -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
|
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
|
-
|
114
|
-
|
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
|
-
|
116
|
+
"XX"
|
118
117
|
else
|
119
|
-
|
118
|
+
" "
|
120
119
|
end
|
121
|
-
}
|
122
|
-
|
123
|
-
}
|
124
|
-
return str
|
120
|
+
}.join + "\n"
|
121
|
+
}.join
|
125
122
|
end
|
126
123
|
end
|
127
124
|
end
|