RSokoban 0.71
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/COPYING +674 -0
- data/README.rdoc +47 -0
- data/TODO +34 -0
- data/bin/rsokoban +10 -0
- data/data/microban.xsb +1838 -0
- data/data/original.xsb +1497 -0
- data/data/test.xsb +30 -0
- data/lib/rsokoban/crate.rb +16 -0
- data/lib/rsokoban/exception.rb +7 -0
- data/lib/rsokoban/game.rb +105 -0
- data/lib/rsokoban/level.rb +269 -0
- data/lib/rsokoban/level_loader.rb +58 -0
- data/lib/rsokoban/level_set.rb +31 -0
- data/lib/rsokoban/man.rb +17 -0
- data/lib/rsokoban/moveable.rb +22 -0
- data/lib/rsokoban/option.rb +93 -0
- data/lib/rsokoban/position.rb +24 -0
- data/lib/rsokoban/raw_level.rb +16 -0
- data/lib/rsokoban/storage.rb +14 -0
- data/lib/rsokoban/ui/console.rb +107 -0
- data/lib/rsokoban/ui/curses_console.rb +123 -0
- data/lib/rsokoban/ui/ui.rb +44 -0
- data/lib/rsokoban.rb +29 -0
- data/test/original.xsb +1497 -0
- data/test/tc_level.rb +773 -0
- data/test/tc_level_loader.rb +88 -0
- data/test/tc_level_set.rb +42 -0
- data/test/tc_man.rb +55 -0
- data/test/tc_moveable.rb +41 -0
- data/test/tc_position.rb +75 -0
- data/test/tc_raw_level.rb +35 -0
- data/test/test.rb +16 -0
- data/test/test_file1.xsb +9 -0
- data/test/test_file2.xsb +49 -0
- data/test/ui/tc_console.rb +75 -0
- metadata +102 -0
data/test/tc_level.rb
ADDED
@@ -0,0 +1,773 @@
|
|
1
|
+
|
2
|
+
class TC_Level < Test::Unit::TestCase
|
3
|
+
|
4
|
+
Text1 = [ '#####',
|
5
|
+
'#.$@#',
|
6
|
+
'#####']
|
7
|
+
|
8
|
+
Text2 = [ '######',
|
9
|
+
'#.$ #',
|
10
|
+
'#.$ #',
|
11
|
+
'#.$ @#',
|
12
|
+
'######']
|
13
|
+
|
14
|
+
Text3 = [ '####',
|
15
|
+
'#..#',
|
16
|
+
'#$$#',
|
17
|
+
'#@ #',
|
18
|
+
'####']
|
19
|
+
|
20
|
+
def test_instance
|
21
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text1))
|
22
|
+
assert_equal true, ins.instance_of?(RSokoban::Level), "Must be an instance of RSokoban::Level"
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_floor_with_Text1
|
26
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text1))
|
27
|
+
expected = [ '#####',
|
28
|
+
'# #',
|
29
|
+
'#####']
|
30
|
+
assert_equal expected, ins.floor
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_floor_with_Text3
|
34
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text3))
|
35
|
+
expected = [ '####',
|
36
|
+
'# #',
|
37
|
+
'# #',
|
38
|
+
'# #',
|
39
|
+
'####']
|
40
|
+
assert_equal expected, ins.floor
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_man_position
|
44
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text1))
|
45
|
+
assert_equal 3, ins.man.x
|
46
|
+
assert_equal 1, ins.man.y
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_crates_is_an_Array
|
50
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text1))
|
51
|
+
assert_equal true, ins.crates.instance_of?(Array), "Must be an Array"
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_crates_with_Text1_must_be_of_size_1
|
55
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text1))
|
56
|
+
assert_equal 1, ins.crates.size
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_crates_contains_some_crate
|
60
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text1))
|
61
|
+
assert_equal true, ins.crates[0].instance_of?(RSokoban::Crate)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_crates_with_Text2_must_be_of_size_3
|
65
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text2))
|
66
|
+
assert_equal 3, ins.crates.size
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_crates_positions
|
70
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text2))
|
71
|
+
assert_equal 2, ins.crates[0].x
|
72
|
+
assert_equal 1, ins.crates[0].y
|
73
|
+
|
74
|
+
assert_equal 2, ins.crates[1].x
|
75
|
+
assert_equal 2, ins.crates[1].y
|
76
|
+
|
77
|
+
assert_equal 2, ins.crates[2].x
|
78
|
+
assert_equal 3, ins.crates[2].y
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_several_crates_on_a_line
|
82
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text3))
|
83
|
+
assert_equal 1, ins.crates[0].x
|
84
|
+
assert_equal 2, ins.crates[0].y
|
85
|
+
|
86
|
+
assert_equal 2, ins.crates[1].x
|
87
|
+
assert_equal 2, ins.crates[1].y
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_storages
|
91
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text1))
|
92
|
+
assert_equal true, ins.storages.instance_of?(Array), "Must be an Array"
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_storages_with_Text1_must_be_of_size_1
|
96
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text1))
|
97
|
+
assert_equal 1, ins.storages.size
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_storages_with_Text2_must_be_of_size_3
|
101
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text2))
|
102
|
+
assert_equal 3, ins.storages.size
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_storages_contains_some_storage
|
106
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text1))
|
107
|
+
assert_equal true, ins.storages[0].instance_of?(RSokoban::Storage)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_storages_positions
|
111
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text2))
|
112
|
+
assert_equal 1, ins.storages[0].x
|
113
|
+
assert_equal 1, ins.storages[0].y
|
114
|
+
|
115
|
+
assert_equal 1, ins.storages[1].x
|
116
|
+
assert_equal 2, ins.storages[1].y
|
117
|
+
|
118
|
+
assert_equal 1, ins.storages[2].x
|
119
|
+
assert_equal 3, ins.storages[2].y
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_several_storages_on_a_line
|
123
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text3))
|
124
|
+
assert_equal 1, ins.storages[0].x
|
125
|
+
assert_equal 1, ins.storages[0].y
|
126
|
+
|
127
|
+
assert_equal 2, ins.storages[1].x
|
128
|
+
assert_equal 1, ins.storages[1].y
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_equality
|
132
|
+
ins1 = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text3))
|
133
|
+
ins2 = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text3))
|
134
|
+
assert ins1 == ins2
|
135
|
+
end
|
136
|
+
|
137
|
+
Level1 = [' #####',
|
138
|
+
' # #',
|
139
|
+
' #$ #',
|
140
|
+
' ### $##',
|
141
|
+
' # $ $ #',
|
142
|
+
'### # ## # ######',
|
143
|
+
'# # ## ##### ..#',
|
144
|
+
'# $ $ ..#',
|
145
|
+
'##### ### #@## ..#',
|
146
|
+
' # #########',
|
147
|
+
' #######']
|
148
|
+
|
149
|
+
def test_rawLevel
|
150
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Level1))
|
151
|
+
assert_equal Level1, ins.picture
|
152
|
+
end
|
153
|
+
|
154
|
+
Level1_u = [' #####',
|
155
|
+
' # #',
|
156
|
+
' #$ #',
|
157
|
+
' ### $##',
|
158
|
+
' # $ $ #',
|
159
|
+
'### # ## # ######',
|
160
|
+
'# # ## ##### ..#',
|
161
|
+
'# $ $ @ ..#',
|
162
|
+
'##### ### # ## ..#',
|
163
|
+
' # #########',
|
164
|
+
' #######']
|
165
|
+
|
166
|
+
def test_rawLevel_after_move_up
|
167
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Level1))
|
168
|
+
ins.move :up
|
169
|
+
assert_equal Level1_u, ins.picture
|
170
|
+
end
|
171
|
+
|
172
|
+
Text4 = [ '####',
|
173
|
+
'#.*#',
|
174
|
+
'#$ #',
|
175
|
+
'#@ #',
|
176
|
+
'####']
|
177
|
+
|
178
|
+
def test_crate_on_storage_at_startup
|
179
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Text4))
|
180
|
+
assert_equal 'WIN move 1', ins.move(:up)
|
181
|
+
end
|
182
|
+
|
183
|
+
### Move up ##############################################
|
184
|
+
|
185
|
+
CanMoveUp1 = ['###',
|
186
|
+
'# #',
|
187
|
+
'#@#',
|
188
|
+
'###']
|
189
|
+
|
190
|
+
AfterMoveUp1 = ['###',
|
191
|
+
'#@#',
|
192
|
+
'# #',
|
193
|
+
'###']
|
194
|
+
|
195
|
+
def test_CanMoveUp1
|
196
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp1))
|
197
|
+
assert_equal 'OK move 1', ins.moveUp
|
198
|
+
assert_equal 1, ins.man.x
|
199
|
+
assert_equal 1, ins.man.y
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_AfterMoveUp1
|
203
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp1))
|
204
|
+
ins.moveUp
|
205
|
+
assert_equal AfterMoveUp1, ins.picture
|
206
|
+
end
|
207
|
+
|
208
|
+
CanMoveUp2 = ['###',
|
209
|
+
'#.#',
|
210
|
+
'#@#',
|
211
|
+
'###']
|
212
|
+
|
213
|
+
AfterMoveUp2 = ['###',
|
214
|
+
'#+#',
|
215
|
+
'# #',
|
216
|
+
'###']
|
217
|
+
|
218
|
+
def test_CanMoveUp2
|
219
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp2))
|
220
|
+
assert_equal 'OK move 1', ins.moveUp
|
221
|
+
assert_equal 1, ins.man.x
|
222
|
+
assert_equal 1, ins.man.y
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_AfterMoveUp2
|
226
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp2))
|
227
|
+
ins.moveUp
|
228
|
+
assert_equal AfterMoveUp2, ins.picture
|
229
|
+
end
|
230
|
+
|
231
|
+
CanMoveUp3 = ['###',
|
232
|
+
'# #',
|
233
|
+
'#$#',
|
234
|
+
'#@#',
|
235
|
+
'###']
|
236
|
+
|
237
|
+
AfterMoveUp3 = ['###',
|
238
|
+
'#$#',
|
239
|
+
'#@#',
|
240
|
+
'# #',
|
241
|
+
'###']
|
242
|
+
|
243
|
+
def test_CanMoveUp3
|
244
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp3))
|
245
|
+
assert_equal 'OK move 1', ins.moveUp
|
246
|
+
assert_equal 1, ins.man.x
|
247
|
+
assert_equal 2, ins.man.y
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_AfterMoveUp3
|
251
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp3))
|
252
|
+
ins.moveUp
|
253
|
+
assert_equal AfterMoveUp3, ins.picture
|
254
|
+
end
|
255
|
+
|
256
|
+
CanMoveUp4 = ['###',
|
257
|
+
'#.#',
|
258
|
+
'#$#',
|
259
|
+
'#@#',
|
260
|
+
'###']
|
261
|
+
|
262
|
+
AfterMoveUp4 = ['###',
|
263
|
+
'#*#',
|
264
|
+
'#@#',
|
265
|
+
'# #',
|
266
|
+
'###']
|
267
|
+
|
268
|
+
def test_CanMoveUp4
|
269
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp4))
|
270
|
+
assert_equal 'WIN move 1', ins.moveUp
|
271
|
+
assert_equal 1, ins.man.x
|
272
|
+
assert_equal 2, ins.man.y
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_AfterMoveUp4
|
276
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveUp4))
|
277
|
+
ins.moveUp
|
278
|
+
assert_equal AfterMoveUp4, ins.picture
|
279
|
+
end
|
280
|
+
|
281
|
+
CannotMoveUp1 = ['###',
|
282
|
+
'#@#',
|
283
|
+
'###']
|
284
|
+
|
285
|
+
def test_CannotMoveUp1
|
286
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp1))
|
287
|
+
assert_equal 'ERROR wall', ins.moveUp
|
288
|
+
assert_equal CannotMoveUp1, ins.picture
|
289
|
+
end
|
290
|
+
|
291
|
+
CannotMoveUp2 = ['###',
|
292
|
+
'#$#',
|
293
|
+
'#@#',
|
294
|
+
'###']
|
295
|
+
|
296
|
+
def test_CannotMoveUp2
|
297
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp2))
|
298
|
+
assert_equal 'ERROR wall behind crate', ins.moveUp
|
299
|
+
assert_equal CannotMoveUp2, ins.picture
|
300
|
+
end
|
301
|
+
|
302
|
+
CannotMoveUp3 = ['###',
|
303
|
+
'# #',
|
304
|
+
'#$#',
|
305
|
+
'#$#',
|
306
|
+
'#@#',
|
307
|
+
'###']
|
308
|
+
|
309
|
+
def test_CannotMoveUp3
|
310
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp3))
|
311
|
+
assert_equal 'ERROR double crate', ins.moveUp
|
312
|
+
assert_equal CannotMoveUp3, ins.picture
|
313
|
+
end
|
314
|
+
|
315
|
+
CannotMoveUp4 = ['###',
|
316
|
+
'# #',
|
317
|
+
'#*#',
|
318
|
+
'#$#',
|
319
|
+
'#@#',
|
320
|
+
'###']
|
321
|
+
|
322
|
+
def test_CannotMoveUp4
|
323
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp4))
|
324
|
+
assert_equal 'ERROR double crate', ins.moveUp
|
325
|
+
assert_equal CannotMoveUp4, ins.picture
|
326
|
+
end
|
327
|
+
|
328
|
+
CannotMoveUp5 = ['###',
|
329
|
+
'# #',
|
330
|
+
'#$#',
|
331
|
+
'#*#',
|
332
|
+
'#@#',
|
333
|
+
'###']
|
334
|
+
|
335
|
+
def test_CannotMoveUp5
|
336
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp5))
|
337
|
+
assert_equal 'ERROR double crate', ins.moveUp
|
338
|
+
assert_equal CannotMoveUp5, ins.picture
|
339
|
+
end
|
340
|
+
|
341
|
+
CannotMoveUp6 = ['###',
|
342
|
+
'# #',
|
343
|
+
'#*#',
|
344
|
+
'#*#',
|
345
|
+
'#@#',
|
346
|
+
'###']
|
347
|
+
|
348
|
+
def test_CannotMoveUp6
|
349
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUp6))
|
350
|
+
assert_equal 'ERROR double crate', ins.moveUp
|
351
|
+
assert_equal CannotMoveUp6, ins.picture
|
352
|
+
end
|
353
|
+
|
354
|
+
### Move down ##############################################
|
355
|
+
|
356
|
+
CanMoveDown1 = ['###',
|
357
|
+
'#@#',
|
358
|
+
'# #',
|
359
|
+
'###']
|
360
|
+
|
361
|
+
AfterMoveDown1 = ['###',
|
362
|
+
'# #',
|
363
|
+
'#@#',
|
364
|
+
'###']
|
365
|
+
|
366
|
+
def test_CanMoveDown1
|
367
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown1))
|
368
|
+
assert_equal 'OK move 1', ins.moveDown
|
369
|
+
end
|
370
|
+
|
371
|
+
def test_AfterMoveDown1
|
372
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown1))
|
373
|
+
ins.moveDown
|
374
|
+
assert_equal AfterMoveDown1, ins.picture
|
375
|
+
end
|
376
|
+
|
377
|
+
CanMoveDown2 = ['###',
|
378
|
+
'#@#',
|
379
|
+
'#.#',
|
380
|
+
'###']
|
381
|
+
|
382
|
+
AfterMoveDown2 = ['###',
|
383
|
+
'# #',
|
384
|
+
'#+#',
|
385
|
+
'###']
|
386
|
+
|
387
|
+
def test_CanMoveDown2
|
388
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown2))
|
389
|
+
assert_equal 'OK move 1', ins.moveDown
|
390
|
+
end
|
391
|
+
|
392
|
+
def test_AfterMoveDown2
|
393
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown2))
|
394
|
+
ins.moveDown
|
395
|
+
assert_equal AfterMoveDown2, ins.picture
|
396
|
+
end
|
397
|
+
|
398
|
+
CanMoveDown3 = ['###',
|
399
|
+
'#@#',
|
400
|
+
'#$#',
|
401
|
+
'# #',
|
402
|
+
'###']
|
403
|
+
|
404
|
+
AfterMoveDown3 = ['###',
|
405
|
+
'# #',
|
406
|
+
'#@#',
|
407
|
+
'#$#',
|
408
|
+
'###']
|
409
|
+
|
410
|
+
def test_CanMoveDown3
|
411
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown3))
|
412
|
+
assert_equal 'OK move 1', ins.moveDown
|
413
|
+
end
|
414
|
+
|
415
|
+
def test_AfterMoveDown3
|
416
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown3))
|
417
|
+
ins.moveDown
|
418
|
+
assert_equal AfterMoveDown3, ins.picture
|
419
|
+
end
|
420
|
+
|
421
|
+
CanMoveDown4 = ['###',
|
422
|
+
'#@#',
|
423
|
+
'#$#',
|
424
|
+
'#.#',
|
425
|
+
'###']
|
426
|
+
|
427
|
+
AfterMoveDown4 = ['###',
|
428
|
+
'# #',
|
429
|
+
'#@#',
|
430
|
+
'#*#',
|
431
|
+
'###']
|
432
|
+
|
433
|
+
def test_CanMoveDown4
|
434
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown4))
|
435
|
+
assert_equal 'WIN move 1', ins.moveDown
|
436
|
+
end
|
437
|
+
|
438
|
+
def test_AfterMoveDown4
|
439
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveDown4))
|
440
|
+
ins.moveDown
|
441
|
+
assert_equal AfterMoveDown4, ins.picture
|
442
|
+
end
|
443
|
+
|
444
|
+
CannotMoveDown1 = ['###',
|
445
|
+
'#@#',
|
446
|
+
'###']
|
447
|
+
|
448
|
+
def test_CannotMoveDown1
|
449
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown1))
|
450
|
+
assert_equal 'ERROR wall', ins.moveDown
|
451
|
+
assert_equal CannotMoveDown1, ins.picture
|
452
|
+
end
|
453
|
+
|
454
|
+
CannotMoveDown2 = ['###',
|
455
|
+
'#@#',
|
456
|
+
'#$#',
|
457
|
+
'###']
|
458
|
+
|
459
|
+
def test_CannotMoveDown2
|
460
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown2))
|
461
|
+
assert_equal 'ERROR wall behind crate', ins.moveDown
|
462
|
+
assert_equal CannotMoveDown2, ins.picture
|
463
|
+
end
|
464
|
+
|
465
|
+
CannotMoveDown3 = ['###',
|
466
|
+
'#@#',
|
467
|
+
'#$#',
|
468
|
+
'#$#',
|
469
|
+
'# #',
|
470
|
+
'###']
|
471
|
+
|
472
|
+
def test_CannotMoveDown3
|
473
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown3))
|
474
|
+
assert_equal 'ERROR double crate', ins.moveDown
|
475
|
+
assert_equal CannotMoveDown3, ins.picture
|
476
|
+
end
|
477
|
+
|
478
|
+
CannotMoveDown4 = ['###',
|
479
|
+
'#@#',
|
480
|
+
'#$#',
|
481
|
+
'#*#',
|
482
|
+
'# #',
|
483
|
+
'###']
|
484
|
+
|
485
|
+
def test_CannotMoveDown4
|
486
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown4))
|
487
|
+
assert_equal 'ERROR double crate', ins.moveDown
|
488
|
+
assert_equal CannotMoveDown4, ins.picture
|
489
|
+
end
|
490
|
+
|
491
|
+
CannotMoveDown5 = ['###',
|
492
|
+
'#@#',
|
493
|
+
'#*#',
|
494
|
+
'#$#',
|
495
|
+
'# #',
|
496
|
+
'###']
|
497
|
+
|
498
|
+
def test_CannotMoveDown5
|
499
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown5))
|
500
|
+
assert_equal 'ERROR double crate', ins.moveDown
|
501
|
+
assert_equal CannotMoveDown5, ins.picture
|
502
|
+
end
|
503
|
+
|
504
|
+
CannotMoveDown6 = ['###',
|
505
|
+
'#@#',
|
506
|
+
'#*#',
|
507
|
+
'#*#',
|
508
|
+
'# #',
|
509
|
+
'###']
|
510
|
+
|
511
|
+
def test_CannotMoveDown6
|
512
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveDown6))
|
513
|
+
assert_equal 'ERROR double crate', ins.moveDown
|
514
|
+
assert_equal CannotMoveDown6, ins.picture
|
515
|
+
end
|
516
|
+
|
517
|
+
### Move left ##############################################
|
518
|
+
|
519
|
+
CanMoveLeft1 = ['####',
|
520
|
+
'# @#',
|
521
|
+
'####']
|
522
|
+
|
523
|
+
AfterMoveLeft1 = ['####',
|
524
|
+
'#@ #',
|
525
|
+
'####']
|
526
|
+
|
527
|
+
def test_CanMoveLeft1
|
528
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft1))
|
529
|
+
assert_equal 'OK move 1', ins.moveLeft
|
530
|
+
end
|
531
|
+
|
532
|
+
def test_AfterMoveLeft1
|
533
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft1))
|
534
|
+
ins.moveLeft
|
535
|
+
assert_equal AfterMoveLeft1, ins.picture
|
536
|
+
end
|
537
|
+
|
538
|
+
CanMoveLeft2 = ['####',
|
539
|
+
'#.@#',
|
540
|
+
'####']
|
541
|
+
|
542
|
+
AfterMoveLeft2 = ['####',
|
543
|
+
'#+ #',
|
544
|
+
'####']
|
545
|
+
|
546
|
+
def test_CanMoveLeft2
|
547
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft2))
|
548
|
+
assert_equal 'OK move 1', ins.moveLeft
|
549
|
+
end
|
550
|
+
|
551
|
+
def test_AfterMoveLeft2
|
552
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft2))
|
553
|
+
ins.moveLeft
|
554
|
+
assert_equal AfterMoveLeft2, ins.picture
|
555
|
+
end
|
556
|
+
|
557
|
+
CanMoveLeft3 = ['#####',
|
558
|
+
'# $@#',
|
559
|
+
'#####']
|
560
|
+
|
561
|
+
AfterMoveLeft3 = ['#####',
|
562
|
+
'#$@ #',
|
563
|
+
'#####']
|
564
|
+
|
565
|
+
def test_CanMoveLeft3
|
566
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft3))
|
567
|
+
assert_equal 'OK move 1', ins.moveLeft
|
568
|
+
end
|
569
|
+
|
570
|
+
def test_AfterMoveLeft3
|
571
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft3))
|
572
|
+
ins.moveLeft
|
573
|
+
assert_equal AfterMoveLeft3, ins.picture
|
574
|
+
end
|
575
|
+
|
576
|
+
CanMoveLeft4 = ['#####',
|
577
|
+
'#.$@#',
|
578
|
+
'#####']
|
579
|
+
|
580
|
+
AfterMoveLeft4 = ['#####',
|
581
|
+
'#*@ #',
|
582
|
+
'#####']
|
583
|
+
|
584
|
+
def test_CanMoveLeft4
|
585
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft4))
|
586
|
+
assert_equal 'WIN move 1', ins.moveLeft
|
587
|
+
end
|
588
|
+
|
589
|
+
def test_AfterMoveLeft4
|
590
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveLeft4))
|
591
|
+
ins.moveLeft
|
592
|
+
assert_equal AfterMoveLeft4, ins.picture
|
593
|
+
end
|
594
|
+
|
595
|
+
CannotMoveLeft1 = ['###',
|
596
|
+
'#@#',
|
597
|
+
'###']
|
598
|
+
|
599
|
+
def test_CannotMoveLeft1
|
600
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveLeft1))
|
601
|
+
assert_equal 'ERROR wall', ins.moveLeft
|
602
|
+
assert_equal CannotMoveLeft1, ins.picture
|
603
|
+
end
|
604
|
+
|
605
|
+
CannotMoveLeft2 = ['####',
|
606
|
+
'#$@#',
|
607
|
+
'####']
|
608
|
+
|
609
|
+
def test_CannotMoveLeft2
|
610
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveLeft2))
|
611
|
+
assert_equal 'ERROR wall behind crate', ins.moveLeft
|
612
|
+
assert_equal CannotMoveLeft2, ins.picture
|
613
|
+
end
|
614
|
+
|
615
|
+
CannotMoveLeft3 = ['######',
|
616
|
+
'# $$@#',
|
617
|
+
'######']
|
618
|
+
|
619
|
+
def test_CannotMoveLeft3
|
620
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveLeft3))
|
621
|
+
assert_equal 'ERROR double crate', ins.moveLeft
|
622
|
+
assert_equal CannotMoveLeft3, ins.picture
|
623
|
+
end
|
624
|
+
|
625
|
+
### Move right ##############################################
|
626
|
+
|
627
|
+
CanMoveRight1 = ['####',
|
628
|
+
'#@ #',
|
629
|
+
'####']
|
630
|
+
|
631
|
+
AfterMoveRight1 = ['####',
|
632
|
+
'# @#',
|
633
|
+
'####']
|
634
|
+
|
635
|
+
def test_CanMoveRight1
|
636
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight1))
|
637
|
+
assert_equal 'OK move 1', ins.moveRight
|
638
|
+
end
|
639
|
+
|
640
|
+
def test_AfterMoveRight1
|
641
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight1))
|
642
|
+
ins.moveRight
|
643
|
+
assert_equal AfterMoveRight1, ins.picture
|
644
|
+
end
|
645
|
+
|
646
|
+
CanMoveRight2 = ['####',
|
647
|
+
'#@.#',
|
648
|
+
'####']
|
649
|
+
|
650
|
+
AfterMoveRight2 = ['####',
|
651
|
+
'# +#',
|
652
|
+
'####']
|
653
|
+
|
654
|
+
def test_CanMoveRight2
|
655
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight2))
|
656
|
+
assert_equal 'OK move 1', ins.moveRight
|
657
|
+
end
|
658
|
+
|
659
|
+
def test_AfterMoveRight2
|
660
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight2))
|
661
|
+
ins.moveRight
|
662
|
+
assert_equal AfterMoveRight2, ins.picture
|
663
|
+
end
|
664
|
+
|
665
|
+
CanMoveRight3 = ['#####',
|
666
|
+
'#@$ #',
|
667
|
+
'#####']
|
668
|
+
|
669
|
+
AfterMoveRight3 = ['#####',
|
670
|
+
'# @$#',
|
671
|
+
'#####']
|
672
|
+
|
673
|
+
def test_CanMoveRight3
|
674
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight3))
|
675
|
+
assert_equal 'OK move 1', ins.moveRight
|
676
|
+
end
|
677
|
+
|
678
|
+
def test_AfterMoveRight3
|
679
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight3))
|
680
|
+
ins.moveRight
|
681
|
+
assert_equal AfterMoveRight3, ins.picture
|
682
|
+
end
|
683
|
+
|
684
|
+
CanMoveRight4 = ['#####',
|
685
|
+
'#@$.#',
|
686
|
+
'#####']
|
687
|
+
|
688
|
+
AfterMoveRight4 = ['#####',
|
689
|
+
'# @*#',
|
690
|
+
'#####']
|
691
|
+
|
692
|
+
def test_CanMoveRight4
|
693
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight4))
|
694
|
+
assert_equal 'WIN move 1', ins.moveRight
|
695
|
+
end
|
696
|
+
|
697
|
+
def test_AfterMoveRight4
|
698
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CanMoveRight4))
|
699
|
+
ins.moveRight
|
700
|
+
assert_equal AfterMoveRight4, ins.picture
|
701
|
+
end
|
702
|
+
|
703
|
+
CannotMoveRight1 = ['###',
|
704
|
+
'#@#',
|
705
|
+
'###']
|
706
|
+
|
707
|
+
def test_CannotMoveRight1
|
708
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveRight1))
|
709
|
+
assert_equal 'ERROR wall', ins.moveRight
|
710
|
+
assert_equal CannotMoveRight1, ins.picture
|
711
|
+
end
|
712
|
+
|
713
|
+
CannotMoveRight2 = ['####',
|
714
|
+
'#@$#',
|
715
|
+
'####']
|
716
|
+
|
717
|
+
def test_CannotMoveRight2
|
718
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveRight2))
|
719
|
+
assert_equal 'ERROR wall behind crate', ins.moveRight
|
720
|
+
assert_equal CannotMoveRight2, ins.picture
|
721
|
+
end
|
722
|
+
|
723
|
+
CannotMoveRight3 = ['######',
|
724
|
+
'#@$$ #',
|
725
|
+
'######']
|
726
|
+
|
727
|
+
def test_CannotMoveRight3
|
728
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveRight3))
|
729
|
+
assert_equal 'ERROR double crate', ins.moveRight
|
730
|
+
assert_equal CannotMoveRight3, ins.picture
|
731
|
+
end
|
732
|
+
|
733
|
+
### WIN ########################################################
|
734
|
+
|
735
|
+
Win1 = ['#####',
|
736
|
+
'#@$.#',
|
737
|
+
'#####']
|
738
|
+
|
739
|
+
def test_solution_avec_une_seule_caisse
|
740
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', Win1))
|
741
|
+
assert_equal 'WIN move 1', ins.moveRight
|
742
|
+
end
|
743
|
+
|
744
|
+
### BUG 1 #######################################
|
745
|
+
|
746
|
+
# I need a 'crate on storage' in 1, 1. But Level#new don't know how to parse this.
|
747
|
+
# This is the picture I really want to test :
|
748
|
+
# ###
|
749
|
+
# #*#
|
750
|
+
# #@#
|
751
|
+
# ###
|
752
|
+
CannotMoveUpBug1 = ['###',
|
753
|
+
'#$#',
|
754
|
+
'#@#',
|
755
|
+
'# #',
|
756
|
+
'#$#',
|
757
|
+
'#.#',
|
758
|
+
'###']
|
759
|
+
|
760
|
+
def test_bug_1
|
761
|
+
ins = RSokoban::Level.new(RSokoban::RawLevel.new('1', CannotMoveUpBug1))
|
762
|
+
# Changing 'o' to '*'
|
763
|
+
def ins.addStorage
|
764
|
+
@storages.push RSokoban::Storage.new(1, 1)
|
765
|
+
end
|
766
|
+
ins.addStorage
|
767
|
+
|
768
|
+
# I need to be sure that coord 1, 1 is '*'
|
769
|
+
assert_equal '#*#', ins.picture[1]
|
770
|
+
|
771
|
+
assert_equal 'ERROR wall behind crate', ins.moveUp
|
772
|
+
end
|
773
|
+
end
|