sokoban 0.0.17 → 0.0.18

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a921867ffc4091581ea2ba07a96d0fd98ede029
4
- data.tar.gz: 7a66174afaff10b372deedbe8dc342348ee0bf57
3
+ metadata.gz: 4c1e7cc5fafc2a73545dcef03810153dd37bb504
4
+ data.tar.gz: 9c7eee8ba0b588cffb5073c87bb2507ee54209c6
5
5
  SHA512:
6
- metadata.gz: 52e6766c2d227cc6aa5beb2afa5c83b22df5156af6413421b2c4bcc5edc3d1f2d8512965fb2f042328e738d085e4e47e3b222355a013b848ece8f5c287140a0d
7
- data.tar.gz: c9aaea1824af81935a5dedd4d45855c0787c0d98e2355cd88340b3bed1c15cf6e2b31ace35c700b70449b0878c69472e208552327d1d113513024f00f4de8ef0
6
+ metadata.gz: 332e0899f91d305e5b7e493ee6125caacae0aa088265c6e02d5799b8911c833b8fecddf92abcec72818692c98a7bc8ce8d4e902112a71d5d244a8365b2d3b30a
7
+ data.tar.gz: 902fdc58e2e3e4526094872e310a612d3ac50f381b1a0bc98ae8ef9b9813db4286a2297609e46c7716ad3bbccc58ffe3ce329a21ff963ce3b2e9e6d0009d766a
data/lib/sokoban.rb CHANGED
@@ -33,7 +33,9 @@ module Sokoban
33
33
  D: { x: 1, y: 0 } # 4
34
34
  }
35
35
 
36
- # Global-ish variables to ease testing
36
+ # Global variables to ease testing
37
+ # I still like to initialize them even though
38
+ # nil is the same as false in an if statement
37
39
  $batch, $hax = false, false
38
40
 
39
41
  # Game class separates logger and optparse from internal
@@ -161,16 +163,12 @@ module Sokoban
161
163
  initialize(lnum)
162
164
  end
163
165
 
164
- def parse_move_string(string)
165
- string.each_char {|c| parse_move(c) }
166
- end
167
-
168
166
  def play
169
167
  while free_boxes > 0
170
168
  print self
171
169
  if $batch
172
170
  # Input a string terminated by newline
173
- parse_move_string(gets.strip)
171
+ parse_move(gets.strip)
174
172
  else
175
173
  # Handle single key press
176
174
  parse_move(STDIN.getch)
@@ -216,6 +214,8 @@ module Sokoban
216
214
  end
217
215
 
218
216
  def parse_move(input)
217
+ # Handle multiple moves
218
+ input.each_char {|c| parse_move(c) } if input.size > 1
219
219
  case input.downcase
220
220
  when 'b'; $batch = ! $batch
221
221
  when 'w', 'k', '8'; move(:W) #UP)
@@ -1,3 +1,3 @@
1
1
  module Sokoban
2
- VERSION = '0.0.17'
2
+ VERSION = '0.0.18'
3
3
  end
@@ -37,20 +37,20 @@ describe Level do
37
37
 
38
38
  it "accepts valid moves" do
39
39
  level = Level.new
40
- level.parse_move_string(INPUT)
40
+ level.parse_move(INPUT)
41
41
  expect(level.moves).to eq(INPUT.size)
42
42
  end
43
43
 
44
44
  it "ignores invalid moves" do
45
45
  level = Level.new
46
- level.parse_move_string(INPUT)
46
+ level.parse_move(INPUT)
47
47
  level.parse_move("F") # shouldn"t increment moves
48
48
  expect(level.moves).to eq(INPUT.size)
49
49
  end
50
50
 
51
51
  it "restarts" do
52
52
  level = Level.new
53
- level.parse_move_string(INPUT)
53
+ level.parse_move(INPUT)
54
54
  expect(level.free_boxes).to eq(1)
55
55
  level.parse_move("R") # restart
56
56
  expect(level.free_boxes).to eq(6)
@@ -58,14 +58,14 @@ describe Level do
58
58
 
59
59
  it "plays level 1" do
60
60
  level = Level.new
61
- level.parse_move_string(INPUT)
61
+ level.parse_move(INPUT)
62
62
  level.parse_move("D") # right
63
63
  expect(level.free_boxes).to eq(0) # Victory!
64
64
  end
65
65
 
66
66
  it "increments pushes on box move" do
67
67
  level = Level.new
68
- level.parse_move_string(INPUT)
68
+ level.parse_move(INPUT)
69
69
  expect(level.pushes).to eq(96)
70
70
  level.parse_move("D") # right
71
71
  expect(level.pushes).to eq(97)
@@ -73,7 +73,7 @@ describe Level do
73
73
 
74
74
  it "decrements pushes on box move undo" do
75
75
  level = Level.new
76
- level.parse_move_string(INPUT)
76
+ level.parse_move(INPUT)
77
77
  level.parse_move("D") # right
78
78
  expect(level.pushes).to eq(97)
79
79
  level.parse_move("U") # undo
@@ -82,7 +82,7 @@ describe Level do
82
82
 
83
83
  it "ignores moves into walls" do
84
84
  level = Level.new
85
- level.parse_move_string(INPUT)
85
+ level.parse_move(INPUT)
86
86
  level.parse_move("A") # left
87
87
  expect(level.moves).to eq(INPUT.size + 1)
88
88
  # Try to move into wall
@@ -92,8 +92,8 @@ describe Level do
92
92
 
93
93
  it "ignores moves into non-free boxes" do
94
94
  level = Level.new
95
- level.parse_move_string(INPUT)
96
- level.parse_move_string("SD")
95
+ level.parse_move(INPUT)
96
+ level.parse_move("SD")
97
97
  expect(level.moves).to eq(INPUT.size + 2)
98
98
  # Try to move into non-free box
99
99
  level.parse_move("D") # right
@@ -102,8 +102,8 @@ describe Level do
102
102
 
103
103
  it "ignores pushes into walls" do
104
104
  level = Level.new
105
- level.parse_move_string(INPUT)
106
- level.parse_move_string("SDW") # down, right, up
105
+ level.parse_move(INPUT)
106
+ level.parse_move("SDW") # down, right, up
107
107
  expect(level.pushes).to eq(97)
108
108
  # Try to push box into wall
109
109
  level.parse_move("W") # up
@@ -112,10 +112,10 @@ describe Level do
112
112
 
113
113
  it "ignores pushes into non-free boxes" do
114
114
  level = Level.new
115
- level.parse_move_string(INPUT)
116
- level.parse_move_string("WDS") # up, right, down
115
+ level.parse_move(INPUT)
116
+ level.parse_move("WDS") # up, right, down
117
117
  expect(level.pushes).to eq(97)
118
- level.parse_move_string("AS") # left, down
118
+ level.parse_move("AS") # left, down
119
119
  # Try to push box into non-free box
120
120
  level.parse_move("D") # right
121
121
  expect(level.pushes).to eq(97)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sokoban
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boohbah