meiro 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +97 -0
- data/Rakefile +11 -0
- data/lib/meiro.rb +20 -0
- data/lib/meiro/block.rb +239 -0
- data/lib/meiro/dungeon.rb +64 -0
- data/lib/meiro/floor.rb +198 -0
- data/lib/meiro/map_layer.rb +117 -0
- data/lib/meiro/options.rb +56 -0
- data/lib/meiro/partition.rb +20 -0
- data/lib/meiro/passage.rb +24 -0
- data/lib/meiro/room.rb +233 -0
- data/lib/meiro/tile.rb +806 -0
- data/lib/meiro/tile_manager.rb +92 -0
- data/lib/meiro/tile_manager/binary_tile_manager.rb +15 -0
- data/lib/meiro/tile_manager/detailed_tile_manager.rb +347 -0
- data/lib/meiro/tile_manager/rogue_like_tile_manager.rb +57 -0
- data/lib/meiro/version.rb +3 -0
- data/meiro.gemspec +25 -0
- data/spec/block_spec.rb +460 -0
- data/spec/dungeon_spec.rb +153 -0
- data/spec/floor_spec.rb +526 -0
- data/spec/map_layer_spec.rb +296 -0
- data/spec/meiro_spec.rb +15 -0
- data/spec/room_spec.rb +564 -0
- data/spec/spec_helper.rb +8 -0
- metadata +137 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class Meiro::MapLayer
|
|
4
|
+
# テスト用にアクセス可能にする
|
|
5
|
+
attr_accessor :map
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe Meiro::MapLayer do
|
|
9
|
+
let(:width) { 10 }
|
|
10
|
+
let(:height) { 5 }
|
|
11
|
+
|
|
12
|
+
describe '.new' do
|
|
13
|
+
context '幅:10、高さ:5の場合' do
|
|
14
|
+
subject { described_class.new(width, height) }
|
|
15
|
+
|
|
16
|
+
its(:map) do
|
|
17
|
+
expect = [[nil,nil,nil,nil,nil,nil,nil,nil,nil,nil],
|
|
18
|
+
[nil,nil,nil,nil,nil,nil,nil,nil,nil,nil],
|
|
19
|
+
[nil,nil,nil,nil,nil,nil,nil,nil,nil,nil],
|
|
20
|
+
[nil,nil,nil,nil,nil,nil,nil,nil,nil,nil],
|
|
21
|
+
[nil,nil,nil,nil,nil,nil,nil,nil,nil,nil],]
|
|
22
|
+
should eq(expect)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
let(:map_layer) { described_class.new(width, height) }
|
|
28
|
+
|
|
29
|
+
describe '#[]' do
|
|
30
|
+
before(:each) { map_layer.map = [[1,2,3],[4,5,6],[7,8,9]] }
|
|
31
|
+
|
|
32
|
+
subject { map_layer[x, y] }
|
|
33
|
+
|
|
34
|
+
[
|
|
35
|
+
[0, 0, 1],
|
|
36
|
+
[1, 0, 2],
|
|
37
|
+
[2, 0, 3],
|
|
38
|
+
[0, 1, 4],
|
|
39
|
+
[1, 1, 5],
|
|
40
|
+
[2, 1, 6],
|
|
41
|
+
[0, 2, 7],
|
|
42
|
+
[1, 2, 8],
|
|
43
|
+
[2, 2, 9],
|
|
44
|
+
].each do |_x, _y, expect|
|
|
45
|
+
context "[#{_x}, #{_y}]にアクセスした場合" do
|
|
46
|
+
let(:x) { _x }
|
|
47
|
+
let(:y) { _y }
|
|
48
|
+
|
|
49
|
+
it { should eq(expect) }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe '#[]=' do
|
|
55
|
+
[
|
|
56
|
+
[0, 0, 1],
|
|
57
|
+
[1, 0, 2],
|
|
58
|
+
[2, 0, 3],
|
|
59
|
+
[0, 1, 4],
|
|
60
|
+
[1, 1, 5],
|
|
61
|
+
[2, 1, 6],
|
|
62
|
+
[0, 2, 7],
|
|
63
|
+
[1, 2, 8],
|
|
64
|
+
[2, 2, 9],
|
|
65
|
+
].each do |_x, _y, v|
|
|
66
|
+
context "[#{_x}, #{_y}]にアクセスした場合" do
|
|
67
|
+
subject { map_layer[_x, _y] = v; map_layer[_x, _y] }
|
|
68
|
+
|
|
69
|
+
it { should eq(v) }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe '#each_line' do
|
|
75
|
+
before(:each) { map_layer.map = [[1,2,3],[4,5,6],[7,8,9]] }
|
|
76
|
+
|
|
77
|
+
subject do
|
|
78
|
+
sub = []
|
|
79
|
+
map_layer.each_line {|line| sub.unshift(line) }
|
|
80
|
+
sub
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it { should eq([[7,8,9],[4,5,6],[1,2,3]]) }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe '#each_tile' do
|
|
87
|
+
before(:each) { map_layer.map = [[1,2,3],[4,5,6],[7,8,9]] }
|
|
88
|
+
|
|
89
|
+
subject do
|
|
90
|
+
sub = [[],[],[]]
|
|
91
|
+
map_layer.each_tile {|x, y, tile| sub[x][y] = tile }
|
|
92
|
+
sub
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it { should eq([[1,4,7],[2,5,8],[3,6,9]]) }
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
class Meiro::BaseMap
|
|
100
|
+
# テスト用にアクセス可能にする
|
|
101
|
+
attr_accessor :map
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe Meiro::BaseMap do
|
|
105
|
+
let(:dungeon) { Meiro::Dungeon.new }
|
|
106
|
+
let(:floor) do
|
|
107
|
+
args = [dungeon, dungeon.width, dungeon.height,
|
|
108
|
+
dungeon.min_room_width, dungeon.min_room_height,
|
|
109
|
+
dungeon.max_room_width, dungeon.max_room_height,]
|
|
110
|
+
Meiro::Floor.new(*args)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
let(:width) { 10 }
|
|
114
|
+
let(:height) { 5 }
|
|
115
|
+
let(:wall_klass) { Meiro::Tile::Wall }
|
|
116
|
+
|
|
117
|
+
describe '.new' do
|
|
118
|
+
context '要素のクラス指定なしの場合' do
|
|
119
|
+
subject { described_class.new(width, height) }
|
|
120
|
+
|
|
121
|
+
its(:map) do
|
|
122
|
+
expect = [[nil,nil,nil,nil,nil,nil,nil,nil,nil,nil],
|
|
123
|
+
[nil,nil,nil,nil,nil,nil,nil,nil,nil,nil],
|
|
124
|
+
[nil,nil,nil,nil,nil,nil,nil,nil,nil,nil],
|
|
125
|
+
[nil,nil,nil,nil,nil,nil,nil,nil,nil,nil],
|
|
126
|
+
[nil,nil,nil,nil,nil,nil,nil,nil,nil,nil],]
|
|
127
|
+
should eq(expect)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
context '要素のクラス指定ありの場合' do
|
|
132
|
+
subject { described_class.new(width, height, wall_klass) }
|
|
133
|
+
|
|
134
|
+
its(:map) do
|
|
135
|
+
subject.each_tile do |x, y, tile|
|
|
136
|
+
tile.should be_instance_of(wall_klass)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
let(:base_map) { described_class.new(width, height, wall_klass) }
|
|
143
|
+
|
|
144
|
+
describe '#fill_rect' do
|
|
145
|
+
let(:klass_1) { class C1; def self.new; 1; end; end; C1 }
|
|
146
|
+
let(:klass_0) { class C0; def self.new; 0; end; end; C0 }
|
|
147
|
+
let(:base_map) { described_class.new(width, height, klass_1) }
|
|
148
|
+
let(:width) { 5 }
|
|
149
|
+
let(:heiht) { 5 }
|
|
150
|
+
|
|
151
|
+
subject do
|
|
152
|
+
base_map.fill_rect(x1, y1, x2, y2, klass_0)
|
|
153
|
+
base_map.map
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
context '線形に処理する場合' do
|
|
157
|
+
let(:x1) { 2 }; let(:y1) { 0 }
|
|
158
|
+
let(:x2) { 2 }; let(:y2) { 4 }
|
|
159
|
+
|
|
160
|
+
it do
|
|
161
|
+
should eq([[1,1,0,1,1],
|
|
162
|
+
[1,1,0,1,1],
|
|
163
|
+
[1,1,0,1,1],
|
|
164
|
+
[1,1,0,1,1],
|
|
165
|
+
[1,1,0,1,1],])
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
context '正方形に処理する場合' do
|
|
170
|
+
let(:x1) { 1 }; let(:y1) { 1 }
|
|
171
|
+
let(:x2) { 3 }; let(:y2) { 3 }
|
|
172
|
+
|
|
173
|
+
it do
|
|
174
|
+
should eq([[1,1,1,1,1],
|
|
175
|
+
[1,0,0,0,1],
|
|
176
|
+
[1,0,0,0,1],
|
|
177
|
+
[1,0,0,0,1],
|
|
178
|
+
[1,1,1,1,1],])
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
describe '#apply_room' do
|
|
184
|
+
let(:klass_1) { class C1; def self.new; 1; end; end; C1 }
|
|
185
|
+
let(:klass_0) { class C0; def self.new; 0; end; end; C0 }
|
|
186
|
+
let(:base_map) { described_class.new(width, height, klass_1) }
|
|
187
|
+
let(:width) { 5 }
|
|
188
|
+
let(:heiht) { 5 }
|
|
189
|
+
let(:block) { Meiro::Block.new(floor, 0, 0, 5, 5) }
|
|
190
|
+
let(:room) { Meiro::Room.new(3, 3) }
|
|
191
|
+
|
|
192
|
+
before(:each) do
|
|
193
|
+
room.block = block
|
|
194
|
+
room.relative_x = 1
|
|
195
|
+
room.relative_y = 1
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
subject do
|
|
199
|
+
base_map.apply_room(room, klass_0)
|
|
200
|
+
base_map.map
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it do
|
|
204
|
+
should eq([[1,1,1,1,1],
|
|
205
|
+
[1,0,0,0,1],
|
|
206
|
+
[1,0,0,0,1],
|
|
207
|
+
[1,0,0,0,1],
|
|
208
|
+
[1,1,1,1,1],])
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
describe '#apply_passage' do
|
|
213
|
+
let(:klass_2) { class C2; def self.new; 2; end; end; C2 }
|
|
214
|
+
let(:klass_1) { class C1; def self.new; 1; end; end; C1 }
|
|
215
|
+
let(:klass_0) { class C0; def self.new; 0; end; end; C0 }
|
|
216
|
+
let(:base_map) { described_class.new(width, height, klass_1) }
|
|
217
|
+
let(:width) { 5 }
|
|
218
|
+
let(:heiht) { 5 }
|
|
219
|
+
let(:block) { Meiro::Block.new(floor, 0, 0, 5, 5) }
|
|
220
|
+
let(:room) { Meiro::Room.new(3, 3) }
|
|
221
|
+
let(:other_room) { Meiro::Room.new(3, 3) }
|
|
222
|
+
|
|
223
|
+
subject do
|
|
224
|
+
base_map.apply_passage([room], klass_2, klass_0)
|
|
225
|
+
base_map.map
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
before(:each) { passages.each {|p| room.all_pass << p } }
|
|
229
|
+
|
|
230
|
+
context '通路のみ' do
|
|
231
|
+
context '1本の場合' do
|
|
232
|
+
let(:passages) { [Meiro::Passage.new(0, 0, 0, 4)] }
|
|
233
|
+
|
|
234
|
+
it do
|
|
235
|
+
should eq([[0,1,1,1,1],
|
|
236
|
+
[0,1,1,1,1],
|
|
237
|
+
[0,1,1,1,1],
|
|
238
|
+
[0,1,1,1,1],
|
|
239
|
+
[0,1,1,1,1],])
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
context '複数の場合' do
|
|
244
|
+
let(:passages) do
|
|
245
|
+
[Meiro::Passage.new(0, 0, 2, 0),
|
|
246
|
+
Meiro::Passage.new(2, 0, 2, 4),
|
|
247
|
+
Meiro::Passage.new(2, 4, 4, 4),]
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
it do
|
|
251
|
+
should eq([[0,0,0,1,1],
|
|
252
|
+
[1,1,0,1,1],
|
|
253
|
+
[1,1,0,1,1],
|
|
254
|
+
[1,1,0,1,1],
|
|
255
|
+
[1,1,0,0,0],])
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
context '通路+出口' do
|
|
261
|
+
context '通路と出口が重ならない場合' do
|
|
262
|
+
before(:each) do
|
|
263
|
+
room.connected_rooms[gate_coordinate] = other_room
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
let(:passages) { [Meiro::Passage.new(0, 0, 0, 4)] }
|
|
267
|
+
let(:gate_coordinate) { [2, 2] }
|
|
268
|
+
|
|
269
|
+
it do
|
|
270
|
+
should eq([[0,1,1,1,1],
|
|
271
|
+
[0,1,1,1,1],
|
|
272
|
+
[0,1,2,1,1],
|
|
273
|
+
[0,1,1,1,1],
|
|
274
|
+
[0,1,1,1,1],])
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
context '通路と出口が重なる場合' do
|
|
279
|
+
before(:each) do
|
|
280
|
+
room.connected_rooms[gate_coordinate] = other_room
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
let(:passages) { [Meiro::Passage.new(0, 0, 0, 4)] }
|
|
284
|
+
let(:gate_coordinate) { [0, 4] }
|
|
285
|
+
|
|
286
|
+
it do
|
|
287
|
+
should eq([[0,1,1,1,1],
|
|
288
|
+
[0,1,1,1,1],
|
|
289
|
+
[0,1,1,1,1],
|
|
290
|
+
[0,1,1,1,1],
|
|
291
|
+
[2,1,1,1,1],])
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
end
|
data/spec/meiro_spec.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Meiro do
|
|
4
|
+
let(:options) { Hash.new }
|
|
5
|
+
|
|
6
|
+
describe '.create_dungeon' do
|
|
7
|
+
subject { described_class.create_dungeon(options) }
|
|
8
|
+
|
|
9
|
+
its(:class) { should eq(Meiro::Dungeon) }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'should have a version number' do
|
|
13
|
+
Meiro::VERSION.should_not be_nil
|
|
14
|
+
end
|
|
15
|
+
end
|
data/spec/room_spec.rb
ADDED
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Meiro::Room do
|
|
4
|
+
let(:dungeon) { Meiro::Dungeon.new }
|
|
5
|
+
let(:floor) do
|
|
6
|
+
args = [dungeon, dungeon.width, dungeon.height,
|
|
7
|
+
dungeon.min_room_width, dungeon.min_room_height,
|
|
8
|
+
dungeon.max_room_width, dungeon.max_room_height,]
|
|
9
|
+
Meiro::Floor.new(*args)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let(:width) { 10 }
|
|
13
|
+
let(:height) { 5 }
|
|
14
|
+
|
|
15
|
+
describe '.new' do
|
|
16
|
+
subject { described_class.new(width, height) }
|
|
17
|
+
|
|
18
|
+
context '正常系' do
|
|
19
|
+
context '汎用値' do
|
|
20
|
+
let(:width) { 10 }
|
|
21
|
+
let(:height) { 5 }
|
|
22
|
+
|
|
23
|
+
its(:width) { should eq(10) }
|
|
24
|
+
its(:height) { should eq(5) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context '最小値' do
|
|
28
|
+
let(:width) { 3 }
|
|
29
|
+
let(:height) { 3 }
|
|
30
|
+
|
|
31
|
+
its(:width) { should eq(3) }
|
|
32
|
+
its(:height) { should eq(3) }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context '異常系' do
|
|
37
|
+
context '幅が小さすぎる場合' do
|
|
38
|
+
let(:width) { 2 }
|
|
39
|
+
|
|
40
|
+
it { expect {subject}.to raise_error }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context '高さが小さすぎる場合' do
|
|
44
|
+
let(:height) { 2 }
|
|
45
|
+
|
|
46
|
+
it { expect {subject}.to raise_error }
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
let(:room) { described_class.new(width, height) }
|
|
52
|
+
|
|
53
|
+
let(:b_x) { 0 }
|
|
54
|
+
let(:b_y) { 0 }
|
|
55
|
+
let(:b_width) { 60 }
|
|
56
|
+
let(:b_height) { 40 }
|
|
57
|
+
let(:parent) { nil }
|
|
58
|
+
let(:block) { Meiro::Block.new(floor, b_x, b_y, b_width, b_height, parent) }
|
|
59
|
+
|
|
60
|
+
let(:relative_x) { 8 }
|
|
61
|
+
let(:relative_y) { 4 }
|
|
62
|
+
|
|
63
|
+
describe '#x' do
|
|
64
|
+
context 'Blockを紐付けていない場合' do
|
|
65
|
+
subject do
|
|
66
|
+
room.relative_x = relative_x
|
|
67
|
+
room.relative_y = relative_y
|
|
68
|
+
room.x
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it { should be_nil }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
context 'Blockを紐付けている場合' do
|
|
75
|
+
subject do
|
|
76
|
+
block.put_room(room)
|
|
77
|
+
room.relative_x = relative_x
|
|
78
|
+
room.relative_y = relative_y
|
|
79
|
+
room.x
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context 'Blockのx座標が0の場合' do
|
|
83
|
+
it 'Roomの相対座標がそのまま絶対座標となる' do
|
|
84
|
+
should eq(8)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context 'Blockのx座標が>0の場合' do
|
|
89
|
+
let(:b_x) { 5 }
|
|
90
|
+
|
|
91
|
+
it 'Blockのx座標にRoomの相対座標を足しあわせたものが絶対座標となる' do
|
|
92
|
+
should eq(13)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe '#y' do
|
|
99
|
+
context 'Blockを紐付けていない場合' do
|
|
100
|
+
subject do
|
|
101
|
+
room.relative_x = relative_x
|
|
102
|
+
room.relative_y = relative_y
|
|
103
|
+
room.y
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it { should be_nil }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context 'Blockを紐付けている場合' do
|
|
110
|
+
subject do
|
|
111
|
+
block.put_room(room)
|
|
112
|
+
room.relative_x = relative_x
|
|
113
|
+
room.relative_y = relative_y
|
|
114
|
+
room.y
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
context 'Blockのx座標が0の場合' do
|
|
118
|
+
it 'Roomの相対座標がそのまま絶対座標となる' do
|
|
119
|
+
should eq(4)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
context 'Blockのx座標が>0の場合' do
|
|
124
|
+
let(:b_y) { 5 }
|
|
125
|
+
|
|
126
|
+
it 'Blockのx座標にRoomの相対座標を足しあわせたものが絶対座標となる' do
|
|
127
|
+
should eq(9)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
describe '#get_all_abs_coordinate' do
|
|
134
|
+
before do
|
|
135
|
+
block.put_room(room)
|
|
136
|
+
room.relative_x = relative_x
|
|
137
|
+
room.relative_y = relative_y
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
subject { room.get_all_abs_coordinate }
|
|
141
|
+
|
|
142
|
+
context 'ブロックの座標が(0,0)、相対座標が(8,4)、幅が10、高さが5の場合' do
|
|
143
|
+
let(:expected_ary) do
|
|
144
|
+
a = []
|
|
145
|
+
(4..8).each {|y| (8..17).each {|x| a << [x, y] } }
|
|
146
|
+
a
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it { should eq(expected_ary) }
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
describe '#block=' do
|
|
154
|
+
subject { room.block = block }
|
|
155
|
+
|
|
156
|
+
context '相対座標を指定していない場合' do
|
|
157
|
+
it { expect{ subject }.not_to raise_error }
|
|
158
|
+
it { should be_instance_of(Meiro::Block) }
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
context '相対座標を指定している場合' do
|
|
162
|
+
let(:width) { 5 }
|
|
163
|
+
let(:height) { 5 }
|
|
164
|
+
let(:b_width) { 10 }
|
|
165
|
+
let(:b_height) { 10 }
|
|
166
|
+
|
|
167
|
+
subject do
|
|
168
|
+
room.relative_x = relative_x
|
|
169
|
+
room.relative_y = relative_y
|
|
170
|
+
room.block = block
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
[
|
|
174
|
+
[1, 1],
|
|
175
|
+
[1, 4],
|
|
176
|
+
[4, 1],
|
|
177
|
+
[4, 4],
|
|
178
|
+
].each do |x, y|
|
|
179
|
+
context "適切な相対座標(#{x}, #{y})が指定されている場合" do
|
|
180
|
+
let(:relative_x) { x }
|
|
181
|
+
let(:relative_y) { y }
|
|
182
|
+
|
|
183
|
+
it { expect{ subject }.not_to raise_error }
|
|
184
|
+
it { should be_instance_of(Meiro::Block) }
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
[
|
|
189
|
+
[0, 0],
|
|
190
|
+
[4, 0],
|
|
191
|
+
[5, 1],
|
|
192
|
+
[0, 4],
|
|
193
|
+
[4, 5],
|
|
194
|
+
[5, 4],
|
|
195
|
+
[9, 9],
|
|
196
|
+
].each do |x, y|
|
|
197
|
+
context "不適切な相対座標(#{x}, #{y})が指定されている場合" do
|
|
198
|
+
let(:relative_x) { x }
|
|
199
|
+
let(:relative_y) { y }
|
|
200
|
+
|
|
201
|
+
it { expect{ subject }.to raise_error }
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
describe '#set_random_coordinate' do
|
|
208
|
+
context 'Blockを紐付けていない場合' do
|
|
209
|
+
subject { room.set_random_coordinate }
|
|
210
|
+
|
|
211
|
+
it { expect{ subject }.to raise_error }
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
context 'Blockを紐付けている場合' do
|
|
215
|
+
let(:randomizer) { Random.new(1) }
|
|
216
|
+
|
|
217
|
+
subject do
|
|
218
|
+
block.put_room(room)
|
|
219
|
+
room.set_random_coordinate(randomizer)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
context '乱数のseedが1, Blockの幅:60、高さ:40の場合' do
|
|
223
|
+
# この条件下では必ず以下の組み合わせになる
|
|
224
|
+
it { should eq([38, 13]) }
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
context '乱数のseedが1, Blockの幅:30、高さ:20の場合' do
|
|
228
|
+
let(:b_width) { 30 }
|
|
229
|
+
let(:b_height) { 20 }
|
|
230
|
+
# この条件下では必ず以下の組み合わせになる
|
|
231
|
+
it { should eq([6, 12]) }
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
context '乱数の幅がないような設定(Blockの幅:12、高さ:7)の場合' do
|
|
235
|
+
let(:width) { 10 }
|
|
236
|
+
let(:height) { 5 }
|
|
237
|
+
let(:b_width) { 12 }
|
|
238
|
+
let(:b_height) { 7 }
|
|
239
|
+
|
|
240
|
+
it { should eq([1, 1]) }
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
describe '#available_x_max' do
|
|
246
|
+
let(:width) { 3 }
|
|
247
|
+
let(:height) { 3 }
|
|
248
|
+
let(:b_x) { 0 }
|
|
249
|
+
let(:b_y) { 0 }
|
|
250
|
+
let(:b_width) { 5 }
|
|
251
|
+
let(:b_height) { 5 }
|
|
252
|
+
|
|
253
|
+
subject do
|
|
254
|
+
room.relative_x = 1
|
|
255
|
+
room.relative_y = 1
|
|
256
|
+
block.put_room(room)
|
|
257
|
+
room.available_x_max
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
context 'Block幅が5、Room幅が3の場合' do
|
|
261
|
+
it { should eq(1) }
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
context 'Block幅が6、Room幅が3の場合' do
|
|
265
|
+
let(:b_width) { 6 }
|
|
266
|
+
it { should eq(2) }
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
describe '#available_y_max' do
|
|
271
|
+
let(:width) { 3 }
|
|
272
|
+
let(:height) { 3 }
|
|
273
|
+
let(:b_x) { 0 }
|
|
274
|
+
let(:b_y) { 0 }
|
|
275
|
+
let(:b_width) { 5 }
|
|
276
|
+
let(:b_height) { 5 }
|
|
277
|
+
|
|
278
|
+
subject do
|
|
279
|
+
room.relative_x = 1
|
|
280
|
+
room.relative_y = 1
|
|
281
|
+
block.put_room(room)
|
|
282
|
+
room.available_y_max
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
context 'Block高さが5、Room高さが3の場合' do
|
|
286
|
+
it { should eq(1) }
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
context 'Block高さが6、Room高さが3の場合' do
|
|
290
|
+
let(:b_height) { 6 }
|
|
291
|
+
it { should eq(2) }
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
describe '#each_coordinate' do
|
|
296
|
+
let(:width) { 3 }
|
|
297
|
+
let(:height) { 3 }
|
|
298
|
+
let(:b_x) { 0 }
|
|
299
|
+
let(:b_y) { 0 }
|
|
300
|
+
let(:b_width) { 5 }
|
|
301
|
+
let(:b_height) { 5 }
|
|
302
|
+
|
|
303
|
+
subject do
|
|
304
|
+
room.relative_x = 1
|
|
305
|
+
room.relative_y = 1
|
|
306
|
+
block.put_room(room)
|
|
307
|
+
sub = []
|
|
308
|
+
room.each_coordinate do |x, y|
|
|
309
|
+
sub << [x, y]
|
|
310
|
+
end
|
|
311
|
+
sub
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
it do
|
|
315
|
+
expected = [[1, 1], [2, 1], [3, 1],
|
|
316
|
+
[1, 2], [2, 2], [3, 2],
|
|
317
|
+
[1, 3], [2, 3], [3, 3],]
|
|
318
|
+
should eq(expected)
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
describe '#generation' do
|
|
323
|
+
subject { room.generation }
|
|
324
|
+
|
|
325
|
+
context 'Blockに割り当てられていない部屋の場合' do
|
|
326
|
+
it { should eq(nil) }
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
context 'Blockに割り当てられている部屋の場合' do
|
|
330
|
+
before do
|
|
331
|
+
room.relative_x = 1
|
|
332
|
+
room.relative_y = 1
|
|
333
|
+
block.put_room(room)
|
|
334
|
+
block.should_receive(:generation).once
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
it { expect{ subject }.not_to raise_error }
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
describe '#partition' do
|
|
342
|
+
subject { room.partition }
|
|
343
|
+
|
|
344
|
+
context 'Blockに割り当てられていない部屋の場合' do
|
|
345
|
+
it { should eq(nil) }
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
context 'Blockに割り当てられている部屋の場合' do
|
|
349
|
+
before do
|
|
350
|
+
room.relative_x = 1
|
|
351
|
+
room.relative_y = 1
|
|
352
|
+
block.put_room(room)
|
|
353
|
+
block.should_receive(:partition).once
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
it { expect{ subject }.not_to raise_error }
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
describe '#brother' do
|
|
361
|
+
subject { room.brother }
|
|
362
|
+
|
|
363
|
+
context 'Blockに割り当てられていない部屋の場合' do
|
|
364
|
+
it { should eq(nil) }
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
context '割り当てられているBlockが分割されたものでない場合' do
|
|
368
|
+
before do
|
|
369
|
+
room.relative_x = 1
|
|
370
|
+
room.relative_y = 1
|
|
371
|
+
block.put_room(room)
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
it { should eq(nil) }
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
context '割り当てられているBlockが分割されたものである場合' do
|
|
378
|
+
let(:parent) { Meiro::Block.new(floor, b_x, b_y, b_width, b_height, nil) }
|
|
379
|
+
let(:block2) { Meiro::Block.new(floor, b_x, b_y, b_width, b_height, parent) }
|
|
380
|
+
let(:room2) { described_class.new(3, 3) }
|
|
381
|
+
|
|
382
|
+
before(:each) do
|
|
383
|
+
room.relative_x = 1
|
|
384
|
+
room.relative_y = 1
|
|
385
|
+
block.put_room(room)
|
|
386
|
+
room2.relative_x = 1
|
|
387
|
+
room2.relative_y = 1
|
|
388
|
+
block2.put_room(room2)
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
context '対象の部屋がupper_leftの場合' do
|
|
392
|
+
before do
|
|
393
|
+
parent.instance_variable_set(:@upper_left, block)
|
|
394
|
+
parent.instance_variable_set(:@lower_right, block2)
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
it { should eq(room2) }
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
context '対象の部屋がupper_leftの場合' do
|
|
401
|
+
before do
|
|
402
|
+
parent.instance_variable_set(:@upper_left, block2)
|
|
403
|
+
parent.instance_variable_set(:@lower_right, block)
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
it { should eq(room2) }
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
def put_and_return_room(block)
|
|
412
|
+
r = described_class.new(3, 3)
|
|
413
|
+
r.relative_x, r.relative_y = 1, 1
|
|
414
|
+
block.put_room(r)
|
|
415
|
+
r
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
describe '#select_partition' do
|
|
419
|
+
let(:root_block) { floor.root_block.separate; floor.root_block }
|
|
420
|
+
|
|
421
|
+
subject { room.select_partition(other) }
|
|
422
|
+
|
|
423
|
+
context '第2世代-第2世代' do
|
|
424
|
+
# +---+---+
|
|
425
|
+
# | 1 | 2 |
|
|
426
|
+
# +---+---+
|
|
427
|
+
let(:block_1) { root_block.upper_left }
|
|
428
|
+
let(:block_2) { root_block.lower_right }
|
|
429
|
+
let(:room_1) { put_and_return_room(block_1) }
|
|
430
|
+
let(:room_2) { put_and_return_room(block_2) }
|
|
431
|
+
|
|
432
|
+
context 'self:1, other:2の場合' do
|
|
433
|
+
let(:room) { room_1 }
|
|
434
|
+
let(:other) { room_2 }
|
|
435
|
+
|
|
436
|
+
it { should eq(root_block.partition) }
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
context 'self:2, other:1の場合' do
|
|
440
|
+
let(:room) { room_1 }
|
|
441
|
+
let(:other) { room_2 }
|
|
442
|
+
|
|
443
|
+
it { should eq(root_block.partition) }
|
|
444
|
+
end
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
context '第3世代-第3世代' do
|
|
448
|
+
# +---+---+
|
|
449
|
+
# | 1 | 3 |
|
|
450
|
+
# +---+---+
|
|
451
|
+
# | 2 | 4 |
|
|
452
|
+
# +---+---+
|
|
453
|
+
let(:block_l) { root_block.upper_left.separate; root_block.upper_left }
|
|
454
|
+
let(:block_r) { root_block.lower_right.separate; root_block.lower_right }
|
|
455
|
+
let(:block_1) { block_l.upper_left }
|
|
456
|
+
let(:block_2) { block_l.lower_right }
|
|
457
|
+
let(:block_3) { block_r.upper_left }
|
|
458
|
+
let(:block_4) { block_r.lower_right }
|
|
459
|
+
let(:room_1) { put_and_return_room(block_1) }
|
|
460
|
+
let(:room_2) { put_and_return_room(block_2) }
|
|
461
|
+
let(:room_3) { put_and_return_room(block_3) }
|
|
462
|
+
let(:room_4) { put_and_return_room(block_4) }
|
|
463
|
+
|
|
464
|
+
context 'self:1, other:2の場合' do
|
|
465
|
+
let(:room) { room_1 }
|
|
466
|
+
let(:other) { room_2 }
|
|
467
|
+
|
|
468
|
+
it { should eq(block_l.partition) }
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
context 'self:1, other:3の場合' do
|
|
472
|
+
let(:room) { room_1 }
|
|
473
|
+
let(:other) { room_3 }
|
|
474
|
+
|
|
475
|
+
it { should eq(root_block.partition) }
|
|
476
|
+
end
|
|
477
|
+
|
|
478
|
+
context 'self:1, other:4の場合' do
|
|
479
|
+
let(:room) { room_1 }
|
|
480
|
+
let(:other) { room_3 }
|
|
481
|
+
|
|
482
|
+
it { should eq(root_block.partition) }
|
|
483
|
+
end
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
context '第2世代-第3世代' do
|
|
487
|
+
# +---+---+
|
|
488
|
+
# | | 2 |
|
|
489
|
+
# | 1 +---+
|
|
490
|
+
# | | 3 |
|
|
491
|
+
# +---+---+
|
|
492
|
+
let(:block_1) { root_block.upper_left }
|
|
493
|
+
let(:block_r) { root_block.lower_right.separate; root_block.lower_right }
|
|
494
|
+
let(:block_2) { block_r.upper_left }
|
|
495
|
+
let(:block_3) { block_r.lower_right }
|
|
496
|
+
let(:room_1) { put_and_return_room(block_1) }
|
|
497
|
+
let(:room_2) { put_and_return_room(block_2) }
|
|
498
|
+
let(:room_3) { put_and_return_room(block_3) }
|
|
499
|
+
|
|
500
|
+
context 'self:1, other:2の場合' do
|
|
501
|
+
let(:room) { room_1 }
|
|
502
|
+
let(:other) { room_2 }
|
|
503
|
+
|
|
504
|
+
it { should eq(root_block.partition) }
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
context 'self:1, other:3の場合' do
|
|
508
|
+
let(:room) { room_1 }
|
|
509
|
+
let(:other) { room_3 }
|
|
510
|
+
|
|
511
|
+
it { should eq(root_block.partition) }
|
|
512
|
+
end
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
context '第2世代-第4世代' do
|
|
516
|
+
# +------+---+---+
|
|
517
|
+
# | | 2 | 3 |
|
|
518
|
+
# | 1 +---+---+
|
|
519
|
+
# | | 4 | 5 |
|
|
520
|
+
# +------+---+---+
|
|
521
|
+
let(:block_1) { root_block.upper_left }
|
|
522
|
+
let(:block_r) { root_block.lower_right.separate; root_block.lower_right }
|
|
523
|
+
let(:block_ru) { block_r.upper_left.separate; block_r.upper_left }
|
|
524
|
+
let(:block_rl) { block_r.lower_right.separate; block_r.lower_right }
|
|
525
|
+
let(:block_2) { block_ru.upper_left }
|
|
526
|
+
let(:block_3) { block_ru.lower_right }
|
|
527
|
+
let(:block_4) { block_rl.upper_left }
|
|
528
|
+
let(:block_5) { block_rl.lower_right }
|
|
529
|
+
let(:room_1) { put_and_return_room(block_1) }
|
|
530
|
+
let(:room_2) { put_and_return_room(block_2) }
|
|
531
|
+
let(:room_3) { put_and_return_room(block_3) }
|
|
532
|
+
let(:room_4) { put_and_return_room(block_4) }
|
|
533
|
+
let(:room_5) { put_and_return_room(block_5) }
|
|
534
|
+
|
|
535
|
+
context 'self:1, other:2の場合' do
|
|
536
|
+
let(:room) { room_1 }
|
|
537
|
+
let(:other) { room_2 }
|
|
538
|
+
|
|
539
|
+
it { should eq(root_block.partition) }
|
|
540
|
+
end
|
|
541
|
+
|
|
542
|
+
context 'self:1, other:3の場合' do
|
|
543
|
+
let(:room) { room_1 }
|
|
544
|
+
let(:other) { room_3 }
|
|
545
|
+
|
|
546
|
+
it { should eq(root_block.partition) }
|
|
547
|
+
end
|
|
548
|
+
|
|
549
|
+
context 'self:1, other:4の場合' do
|
|
550
|
+
let(:room) { room_1 }
|
|
551
|
+
let(:other) { room_4 }
|
|
552
|
+
|
|
553
|
+
it { should eq(root_block.partition) }
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
context 'self:1, other:5の場合' do
|
|
557
|
+
let(:room) { room_1 }
|
|
558
|
+
let(:other) { room_5 }
|
|
559
|
+
|
|
560
|
+
it { should eq(root_block.partition) }
|
|
561
|
+
end
|
|
562
|
+
end
|
|
563
|
+
end
|
|
564
|
+
end
|