sokobanrb 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sokoban.rb ADDED
@@ -0,0 +1,10 @@
1
+ $: << File.dirname(__FILE__)
2
+
3
+ #require 'set'
4
+
5
+ require 'sokoban/game_engine'
6
+ require 'sokoban/render'
7
+ require 'sokoban/config'
8
+
9
+
10
+
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/sokobanrb/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sokobanrb.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,3 @@
1
+ module Sokobanrb
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "sokobanrb/version"
2
+
3
+ module Sokobanrb
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sokobanrb/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sokobanrb"
7
+ s.version = Sokobanrb::VERSION
8
+ s.authors = ["brownman"]
9
+ s.email = ["ofer.shaham@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{TODO: Write a gem summary}
12
+ s.description = %q{TODO: Write a gem description}
13
+
14
+ s.rubyforge_project = "sokobanrb"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
data/sokobanrb.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ #require "sokoban/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sokobanrb"
7
+ s.version = "0.0.3"
8
+ s.authors = ["brownman"]
9
+
10
+ s.email = ["ofer.shaham@gmail.com"]
11
+
12
+ s.homepage = "https://github.com/brownman/sokoban.rb"
13
+
14
+
15
+ s.summary = %q{just adding code to ruby quiz 5 solution of James Edward Gray II from grayproductions.net }
16
+ s.description = %q{in order to have fun playing with opengl, i use existing sokoban project , so no rights have reserved for me :(}
17
+
18
+
19
+ s.executables = ["sokobanrb"]
20
+
21
+
22
+ if RUBY_VERSION == "1.9.1"
23
+ s.add_development_dependency "ruby-opengl"
24
+ elsif RUBY_VERSION == "1.9.2"
25
+ s.add_development_dependency "ffi-opengl"
26
+ end
27
+
28
+
29
+ s.files = `git ls-files`.split("\n")
30
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
31
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
32
+ s.require_paths = ["lib"]
33
+ end
@@ -0,0 +1,477 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ #describe String do
4
+ #it "should wrap text at white space when over a specific character length" do
5
+ #"foo bar blah".hard_wrap(10).should == "foo bar\nblah"
6
+ #end
7
+ #end
8
+
9
+ #require 'Sokoban'
10
+
11
+ describe Sokoban1::Sokoban do
12
+
13
+ before(:each) do
14
+ @game = Sokoban1::Sokoban.new
15
+ end
16
+
17
+ it 'should create a new instance of the game model' do
18
+ @game.class.should == Sokoban1::Sokoban
19
+ end
20
+
21
+ it 'should load first level' do
22
+ @game.load_level
23
+ @game.display.should == <<-MAP
24
+ ############
25
+ #.. # ###
26
+ #.. # o o #
27
+ #.. #o#### #
28
+ #.. @ ## #
29
+ #.. # # o ##
30
+ ###### ##o o #
31
+ # o o o o #
32
+ # # #
33
+ ############
34
+ MAP
35
+ end
36
+
37
+
38
+ it 'should set game charecter with a char' do
39
+ Sokoban1::Sokoban::CRATE.should == 'o'
40
+ end
41
+
42
+ it 'should keep the board as it is' do
43
+
44
+ board_st = "###\n" +
45
+ "# #\n" +
46
+ "###"
47
+
48
+ b = Sokoban.new(board_st)
49
+
50
+ b.current_board.should == board_st
51
+
52
+ end
53
+
54
+ it "should go left" do
55
+ board_st = "####\n" +
56
+ "# x#\n" +
57
+ "####"
58
+
59
+ board_st_result = "####\n" +
60
+ "#x #\n" +
61
+ "####"
62
+
63
+ b = Sokoban.new(board_st)
64
+ b.left
65
+ b.current_board.should == board_st_result
66
+ end
67
+
68
+ it "should go left considering player column" do
69
+ board_st = "#####\n" +
70
+ "# x#\n" +
71
+ "#####"
72
+
73
+ board_st_result = "#####\n" +
74
+ "# x #\n" +
75
+ "#####"
76
+
77
+ b = Sokoban.new(board_st)
78
+ b.left
79
+ b.current_board.should == board_st_result
80
+ end
81
+
82
+ it "should go left considering player line" do
83
+ board_st = "#####\n" +
84
+ "# #\n" +
85
+ "# x#\n" +
86
+ "#####"
87
+
88
+ board_st_result = "#####\n" +
89
+ "# #\n" +
90
+ "# x #\n" +
91
+ "#####"
92
+
93
+ b = Sokoban.new(board_st)
94
+ b.left
95
+ b.current_board.should == board_st_result
96
+ end
97
+
98
+ it "should not go left through the wall" do
99
+ board_st = "#####\n" +
100
+ "#x #\n" +
101
+ "#####"
102
+
103
+ b = Sokoban.new(board_st)
104
+ b.left
105
+ b.current_board.should == board_st
106
+ end
107
+
108
+ it "should go right" do
109
+ board_st = "####\n" +
110
+ "#x #\n" +
111
+ "####"
112
+
113
+ board_st_result = "####\n" +
114
+ "# x#\n" +
115
+ "####"
116
+
117
+ b = Sokoban.new(board_st)
118
+ b.right
119
+ b.current_board.should == board_st_result
120
+ end
121
+
122
+
123
+ it "should go up" do
124
+ board_st = "####\n" +
125
+ "# #\n" +
126
+ "#x #\n" +
127
+ "####"
128
+
129
+ board_st_result = "####\n" +
130
+ "#x #\n" +
131
+ "# #\n" +
132
+ "####"
133
+
134
+ b = Sokoban.new(board_st)
135
+ b.up
136
+ b.current_board.should == board_st_result
137
+ end
138
+
139
+ it "should go down" do
140
+ board_st = "####\n" +
141
+ "#x #\n" +
142
+ "# #\n" +
143
+ "####"
144
+
145
+ board_st_result = "####\n" +
146
+ "# #\n" +
147
+ "#x #\n" +
148
+ "####"
149
+
150
+ b = Sokoban.new(board_st)
151
+ b.down
152
+ b.current_board.should == board_st_result
153
+ end
154
+
155
+ it "should walk down in a bigger board" do
156
+ board_st = "#####\n" +
157
+ "# #\n" +
158
+ "# x #\n" +
159
+ "# #\n" +
160
+ "#####"
161
+
162
+ board_st_result = "#####\n" +
163
+ "# #\n" +
164
+ "# #\n" +
165
+ "# x #\n" +
166
+ "#####"
167
+
168
+ b = Sokoban.new(board_st)
169
+ b.down
170
+ b.current_board.should == board_st_result
171
+ end
172
+
173
+ it "pushes the crate downward" do
174
+ board_st = "#####\n" +
175
+ "# x #\n" +
176
+ "# c #\n" +
177
+ "# #\n" +
178
+ "#####"
179
+
180
+ board_st_result = "#####\n" +
181
+ "# #\n" +
182
+ "# x #\n" +
183
+ "# c #\n" +
184
+ "#####"
185
+
186
+ b = Sokoban.new(board_st)
187
+ b.down
188
+ b.current_board.should == board_st_result
189
+ end
190
+
191
+ it "should not push the crate down against the wall" do
192
+ board_st = "#####\n" +
193
+ "# #\n" +
194
+ "# x #\n" +
195
+ "# c #\n" +
196
+ "#####"
197
+
198
+ b = Sokoban.new(board_st)
199
+ b.down
200
+ b.current_board.should == board_st
201
+ end
202
+
203
+ it "pushes the crate upwards" do
204
+ board_st = "#####\n" +
205
+ "# #\n" +
206
+ "# c #\n" +
207
+ "# x #\n" +
208
+ "#####"
209
+
210
+ board_st_result = "#####\n" +
211
+ "# c #\n" +
212
+ "# x #\n" +
213
+ "# #\n" +
214
+ "#####"
215
+
216
+ b = Sokoban.new(board_st)
217
+ b.up
218
+ b.current_board.should == board_st_result
219
+ end
220
+
221
+ it "should not push the crate up against the wall" do
222
+ board_st = "#####\n" +
223
+ "# c #\n" +
224
+ "# x #\n" +
225
+ "# #\n" +
226
+ "#####"
227
+
228
+ b = Sokoban.new(board_st)
229
+ b.up
230
+ b.current_board.should == board_st
231
+ end
232
+
233
+
234
+ it "pushes the crate right" do
235
+ board_st = "#####\n" +
236
+ "# #\n" +
237
+ "#xc #\n" +
238
+ "# #\n" +
239
+ "#####"
240
+
241
+ board_st_result = "#####\n" +
242
+ "# #\n" +
243
+ "# xc#\n" +
244
+ "# #\n" +
245
+ "#####"
246
+
247
+ b = Sokoban.new(board_st)
248
+ b.right
249
+ b.current_board.should == board_st_result
250
+ end
251
+
252
+ it "should not push the crate right against the wall" do
253
+ board_st = "#####\n" +
254
+ "# #\n" +
255
+ "# xc#\n" +
256
+ "# #\n" +
257
+ "#####"
258
+
259
+ b = Sokoban.new(board_st)
260
+ b.right
261
+ b.current_board.should == board_st
262
+ end
263
+
264
+ it "pushes the crate to the left" do
265
+ board_st = "#####\n" +
266
+ "# #\n" +
267
+ "# cx#\n" +
268
+ "# #\n" +
269
+ "#####"
270
+
271
+ board_st_result = "#####\n" +
272
+ "# #\n" +
273
+ "#cx #\n" +
274
+ "# #\n" +
275
+ "#####"
276
+
277
+ b = Sokoban.new(board_st)
278
+ b.left
279
+ b.current_board.should == board_st_result
280
+ end
281
+
282
+ it "should not push the crate to the left against the wall" do
283
+ board_st = "#####\n" +
284
+ "# #\n" +
285
+ "#cx #\n" +
286
+ "# #\n" +
287
+ "#####"
288
+
289
+ b = Sokoban.new(board_st)
290
+ b.left
291
+ b.current_board.should == board_st
292
+ end
293
+
294
+ it "should not push the crate down over another crate" do
295
+ board_st = "#####\n" +
296
+ "# x #\n" +
297
+ "# c #\n" +
298
+ "# c #\n" +
299
+ "# #\n" +
300
+ "#####"
301
+
302
+ b = Sokoban.new(board_st)
303
+ b.down
304
+ b.current_board.should == board_st
305
+ end
306
+
307
+ it "should not push the crate up over another crate" do
308
+ board_st = "#####\n" +
309
+ "# #\n" +
310
+ "# c #\n" +
311
+ "# c #\n" +
312
+ "# x #\n" +
313
+ "#####"
314
+
315
+ b = Sokoban.new(board_st)
316
+ b.up
317
+ b.current_board.should == board_st
318
+ end
319
+
320
+ it "should recognize a crate on top of a goal" do
321
+ board_st = "#####\n" +
322
+ "# #\n" +
323
+ "# . #\n" +
324
+ "# c #\n" +
325
+ "# x #\n" +
326
+ "#####"
327
+
328
+ board_st_result = "#####\n" +
329
+ "# #\n" +
330
+ "# o #\n" +
331
+ "# x #\n" +
332
+ "# #\n" +
333
+ "#####"
334
+
335
+ b = Sokoban.new(board_st)
336
+ b.up
337
+ b.current_board.should == board_st_result
338
+ end
339
+
340
+ it "should recognize a player on top of a goal" do
341
+ board_st = "#####\n" +
342
+ "# #\n" +
343
+ "# . #\n" +
344
+ "# x #\n" +
345
+ "# #\n" +
346
+ "#####"
347
+
348
+ board_st_result = "#####\n" +
349
+ "# #\n" +
350
+ "# x #\n" +
351
+ "# #\n" +
352
+ "# #\n" +
353
+ "#####"
354
+
355
+ b = Sokoban.new(board_st)
356
+ b.up
357
+ b.current_board.should == board_st_result
358
+ b.down
359
+ b.current_board.should == board_st
360
+ end
361
+
362
+ it "should recognize a player on top of a goal" do
363
+ board_st = "#####\n" +
364
+ "# . #\n" +
365
+ "# . #\n" +
366
+ "# x #\n" +
367
+ "# #\n" +
368
+ "#####"
369
+
370
+ board_st_result = "#####\n" +
371
+ "# .x#\n" +
372
+ "# . #\n" +
373
+ "# #\n" +
374
+ "# #\n" +
375
+ "#####"
376
+
377
+ b = Sokoban.new(board_st)
378
+ b.up
379
+ b.up
380
+ b.right
381
+ b.current_board.should == board_st_result
382
+ end
383
+
384
+ it "should not remove a crate when exiting a goal" do
385
+ board_st = "#####\n" +
386
+ "# #\n" +
387
+ "# . #\n" +
388
+ "# c #\n" +
389
+ "# x #\n" +
390
+ "#####"
391
+
392
+ board_st_result = "#####\n" +
393
+ "# c #\n" +
394
+ "# x #\n" +
395
+ "# #\n" +
396
+ "# #\n" +
397
+ "#####"
398
+
399
+ b = Sokoban.new(board_st)
400
+ b.up
401
+ b.up
402
+ b.current_board.should == board_st_result
403
+ end
404
+
405
+ it "should not lose that a crate is above a goal after a second movement" do
406
+ board_st = "#####\n" +
407
+ "# . #\n" +
408
+ "# . #\n" +
409
+ "# c #\n" +
410
+ "# x #\n" +
411
+ "#####"
412
+
413
+ board_st_result = "#####\n" +
414
+ "# o #\n" +
415
+ "# x #\n" +
416
+ "# #\n" +
417
+ "# #\n" +
418
+ "#####"
419
+
420
+ b = Sokoban.new(board_st)
421
+ b.up
422
+ b.up
423
+ b.current_board.should == board_st_result
424
+ end
425
+
426
+ it "should be fail by default" do
427
+ board_st = "#####\n" +
428
+ "#c. #\n" +
429
+ "# x #\n" +
430
+ "#####"
431
+
432
+ b = Sokoban.new(board_st)
433
+ b.is_finished.should == false
434
+ end
435
+
436
+ it "should win with a single achievable goal" do
437
+ board_st = "#####\n" +
438
+ "# . #\n" +
439
+ "# c #\n" +
440
+ "# x #\n" +
441
+ "#####"
442
+
443
+ b = Sokoban.new(board_st)
444
+ b.up
445
+ b.is_finished.should == true
446
+ end
447
+
448
+ it "should win with a single achievable goal in another goal point" do
449
+ board_st = "#####\n" +
450
+ "# #\n" +
451
+ "# . #\n" +
452
+ "# c #\n" +
453
+ "# x #\n" +
454
+ "#####"
455
+
456
+ b = Sokoban.new(board_st)
457
+ b.up
458
+ b.is_finished.should == true
459
+ end
460
+
461
+ it "should not win when there are more crates to put into goals" do
462
+ board_st = "#####\n" +
463
+ "# #\n" +
464
+ "# ..#\n" +
465
+ "# cc#\n" +
466
+ "# x #\n" +
467
+ "#####"
468
+
469
+ b = Sokoban.new(board_st)
470
+ b.up
471
+ b.down
472
+ b.right
473
+ b.is_finished.should == false
474
+ end
475
+
476
+ end
477
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require File.dirname(__FILE__) + '/../lib/sokoban'
4
+
5
+ #Spec::Runner.configure do |config|
6
+ #config.mock_with :mocha
7
+ #config.before(:each) do
8
+ #RubyWarrior::Config.reset
9
+ #end
10
+ #end
@@ -0,0 +1,38 @@
1
+ require 'test/unit'
2
+ require 'sokoban'
3
+
4
+ class BoardTest < Test::Unit::TestCase
5
+ include Sokoban
6
+
7
+ def setup
8
+ @board = new_board_from_file('easy.skn')
9
+ end
10
+
11
+ def test_board_parser
12
+ expected_board = "#####\n" +
13
+ "#.o@#\n" +
14
+ "#####"
15
+ assert_equal expected_board, @board.to_s
16
+ end
17
+
18
+ def test_win
19
+ assert !@board.win?
20
+ @board.push(:left)
21
+ expected_board = "#####\n" +
22
+ "#*@ #\n" +
23
+ "#####"
24
+ assert @board.win?
25
+ assert_equal expected_board, @board.to_s
26
+ end
27
+
28
+ def test_storage_cells
29
+ cells = @board.storage_cells
30
+ cell = cells.first
31
+ assert_equal 1, cells.size
32
+ assert_equal [1, 1], cell.coordinates
33
+ assert_nil cell.contents
34
+ @board.push(:left)
35
+ assert cell.contents
36
+ assert_equal :package, cell.contents.type
37
+ end
38
+ end
@@ -0,0 +1,41 @@
1
+ require "../lib/rsokoban/moveable"
2
+
3
+ class TC_Moveable < Test::Unit::TestCase
4
+
5
+ class Foo
6
+ include RSokoban::Moveable
7
+ attr_reader :x, :y
8
+ def initialize
9
+ @x = 12
10
+ @y = 3
11
+ end
12
+ end
13
+
14
+ def testUp
15
+ pos = Foo.new
16
+ pos.up
17
+ assert_equal 12, pos.x
18
+ assert_equal 2, pos.y
19
+ end
20
+
21
+ def testDown
22
+ pos = Foo.new
23
+ pos.down
24
+ assert_equal 12, pos.x
25
+ assert_equal 4, pos.y
26
+ end
27
+
28
+ def testLeft
29
+ pos = Foo.new
30
+ pos.left
31
+ assert_equal 11, pos.x
32
+ assert_equal 3, pos.y
33
+ end
34
+
35
+ def testRight
36
+ pos = Foo.new
37
+ pos.right
38
+ assert_equal 13, pos.x
39
+ assert_equal 3, pos.y
40
+ end
41
+ end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
+ require "rsokoban"
5
+
6
+ require "test/unit"
7
+
8
+ require "../test/tc_level"
9
+ require "../test/tc_set_loader"
10
+ require "../test/tc_level_set"
11
+ require "../test/tc_raw_level"
12
+ require "../test/tc_position"
13
+ require "../test/tc_moveable"
14
+ require "../test/tc_man"
15
+ require "../test/tc_move_recorder"
16
+ require "../test/tc_map"
17
+ require "../test/ui/tc_console"
18
+ require "../test/ui/tc_player_action"
19
+ require "../test/ui/tc_skin"
20
+ require "../test/tc_extensions"
21
+ require "../test/tc_move_result"
22
+ require "../test/tc_game"
23
+ require "../test/tc_game_ui"
24
+ require "../test/tc_game_gui"
25
+ require "../test/tc_game_factory"
26
+ require "../test/tc_layered_map"
27
+ require "../test/tc_record"
28
+ require "../test/tc_install"