bfs_brute_force 0.1.0 → 0.2.0

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: d9930b15a9a8a806ab35bd20859d81154d3cd8c2
4
- data.tar.gz: 5f86c835cef8195335c7c522bce1b4b9b3d60f09
3
+ metadata.gz: 7f879c91d242290c63e4954462f7c59bf549f6ab
4
+ data.tar.gz: 776c1866683f05ecddf9abaa3d2e14dc83c99e51
5
5
  SHA512:
6
- metadata.gz: 482eaa39bd9e01336086bb52ef921f811b43166095bb5268db83c0b46a8b3728d924b4e23d9c1419810dc7bcdff9d65ad4aa6a111ad6bb2c35a4148820f2ef67
7
- data.tar.gz: f4118407512dc990b627e8fb5479de802c89601d73d9f9f6eccefa5514cf50d453995fd8a25c3bbd59519e095427949c361775e82e262e33649f46cd87d148a9
6
+ metadata.gz: 05b9e57c22e4ced97848b53ec57049cc281e4fb40ab9e3bee0009b3c9744709a67d1a8cefed45c000940afca6a5ab214cf9b80b38e3c81f4d312e6cbda6ccfbe
7
+ data.tar.gz: c9cdbccc02109c2bc20735bf5e8730de003ee35a1cf184f309303baab0113e6a8e6a3939c1d1e7be24fecd1d35a75515e5caea649ab98a5afe9c55ecb9577eb5
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ example/Gemfile.lock
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # BfsBruteForce
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/bfs_brute_force.png)](http://badge.fury.io/rb/bfs_brute_force)
4
+
3
5
  Lazy breadth first brute force search for solutions to puzzles.
4
6
 
5
7
  This ruby gem provides an API for representing the initial state
@@ -32,41 +34,47 @@ Each instance of your State subclass must:
32
34
  2. Determine if the state is a win condition of the puzzle (```solved?```)
33
35
  3. Provide a generator for reaching all possible next states (```next_states```)
34
36
 
35
- ### Example Puzzle
37
+ ### Simple Addition Example Puzzle
36
38
 
37
- Imagine a simple puzzle where you are given a starting number, an
38
- ending number, and you can only perform one of three addition
39
- operations (adding one, ten, or one hundred).
39
+ Using the moves "Add 10" and "Add 1," find the shortest number
40
+ of moves from a starting number to a final number.
40
41
 
41
42
  To use ```BfsBruteForce``` you will create your
42
43
  ```BfsBruteForce::State``` subclass as follows:
43
- require 'bfs_brute_force'
44
44
 
45
45
  class AdditionPuzzleState < BfsBruteForce::State
46
- attr_reader :value
47
-
48
- def initialize(start, final)
49
- @start = start
50
- @value = start
46
+ def initialize(value, final)
47
+ @value = value
51
48
  @final = final
52
49
  end
53
-
50
+
51
+ # (see BfsBruteForce::State.solved?)
54
52
  def solved?
55
53
  @value == @final
56
54
  end
57
-
58
- def to_s
59
- "<#{self.class} puzzle from #{@start} to #{@final}>"
60
- end
61
-
55
+
56
+ # Call yield for every next state in your puzzle
57
+ # This puzzle has two legal moves from every state: Add 10, and Add 1
58
+ #
59
+ # (see BfsBruteForce::State.next_states)
62
60
  def next_states(already_seen)
61
+ # If there are no more available states to analyze,
62
+ # {BfsBruteForce::Solver#solve} will throw a {BfsBruteForce::NoSolution}
63
+ # exception.
63
64
  return if @value > @final
64
-
65
- [1, 10, 100].each do |n|
66
- new_value = @value + n
67
- if already_seen.add?(new_value)
68
- yield "Add #{n}", AdditionPuzzleState.new(new_value, @final)
69
- end
65
+
66
+ # already_seen is a set passed to every call of next_states.
67
+ # You can use this set to record which states you have previously
68
+ # visited, from a shorter path, avoiding having to visit that
69
+ # same state again.
70
+ #
71
+ # Set#add?(x) will return nil if x is already in the set
72
+ if already_seen.add?(@value + 10)
73
+ yield "Add 10", AdditionPuzzleState.new(@value + 10, @final)
74
+ end
75
+
76
+ if already_seen.add?(@value + 1)
77
+ yield "Add 1", AdditionPuzzleState.new(@value + 1, @final)
70
78
  end
71
79
  end
72
80
  end
@@ -80,7 +88,7 @@ evaluated state is already known to not be a solution.
80
88
  Inside of ```next_states``` you should yield two arguments for every
81
89
  valid next state of the puzzle:
82
90
 
83
- 1. A string, naming the move required to get to the next state
91
+ 1. A user defined string, naming the move required to get to the next state
84
92
  2. The next state, as a new instance of your ```BfsBruteForce::State``` class.
85
93
 
86
94
  Now that you have your ```BfsBruteForce::State``` class, you can
@@ -89,13 +97,77 @@ initialize it with your starting puzzle state, and pass it to
89
97
  has a ```moves``` method, which returns an array of the move
90
98
  names yielded by your ```next_states``` method:
91
99
 
92
- solver = BfsBruteForce::Solver.new
93
- solution = solver.solve(AdditionPuzzleState.new(0, 42))
100
+ # Find shortest path from 0 to 42
101
+ initial_state = AdditionPuzzleState.new 0, 42
102
+
103
+ solver = BfsBruteForce::Solver.new
104
+ moves = solver.solve(initial_state).moves
94
105
 
95
- solution.moves.each_with_index do |move, index|
96
- puts "Move %02d) %s" % [index + 1, move]
106
+ moves.each_with_index do |move, index|
107
+ puts "Move %d) %s" % [index + 1, move]
97
108
  end
98
109
 
110
+ Running this code will produce the following output:
111
+
112
+ Move 1) Add 10
113
+ Move 2) Add 10
114
+ Move 3) Add 10
115
+ Move 4) Add 10
116
+ Move 5) Add 1
117
+ Move 6) Add 1
118
+
119
+ See [example/simple_addition.rb](example/simple_addition.rb) for the full solution.
120
+
121
+ ### Two Knights Example Puzzle
122
+
123
+ Swap the white and black knights, using standard chess moves.
124
+ This is the "two knights" puzzle from an old video game, The 11th Hour.
125
+
126
+ Initial board layout:
127
+
128
+ +----+
129
+ 4 | BK |
130
+ +----+----+----+----+
131
+ 3 | | | | WK |
132
+ +----+----+----+----+
133
+ 2 | BK | WK | |
134
+ +----+----+----+
135
+ 1 | | |
136
+ +----+----+
137
+ a b c d
138
+
139
+ BK = Black Knight
140
+ WK = White Knight
141
+
142
+ See [example/two_knights.rb](example/two_knights.rb) for a working solution.
143
+
144
+ ### Four Bishops Example Puzzle
145
+
146
+ Swap black and white bishops, following standard chess movement
147
+ rules, except that bishops may not move to a square that would allow
148
+ them to be captured by an enemy bishop (they may not put themselves
149
+ in "check").
150
+
151
+ This is the "four bishops" puzzle from an old video game, The 7th Guest.
152
+
153
+ Initial Board layout:
154
+
155
+ +----+----+----+----+----+
156
+ 4 | BB | | | | WB |
157
+ +----+----+----+----+----+
158
+ 3 | BB | | | | WB |
159
+ +----+----+----+----+----+
160
+ 2 | BB | | | | WB |
161
+ +----+----+----+----+----+
162
+ 1 | BB | | | | WB |
163
+ +----+----+----+----+----+
164
+ a b c d e
165
+
166
+ BB = Black Bishop
167
+ WB = White Bishop
168
+
169
+ See [example/four_bishops.rb](example/four_bishops.rb) for a working solution.
170
+
99
171
  ## License
100
172
 
101
173
  Copyright (c) 2014 Joe Sortelli
@@ -0,0 +1 @@
1
+ bfs_brute_force-example
@@ -0,0 +1 @@
1
+ ruby-2.1.4
data/example/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Use gem from the source code in this git repo
4
+ gem 'bfs_brute_force',
5
+ :git => File.join(File.dirname(__FILE__), '..'),
6
+ :branch => 'HEAD'
data/example/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # BfsBruteForce Example Code
2
+
3
+ These examples can be run directly, if you have installed the gem
4
+ in your local environment.
5
+
6
+ % gem install bfs_brute_force
7
+ % ./two_knights.rb
8
+
9
+ Or you can run the examples against the latest source in your local
10
+ ```bfs_brute_force``` git repo, by using the ```run_example.rb```
11
+ script, which will use ```bundler``` to load the gem from source.
12
+
13
+ % ./run_example.rb two_knights.rb
@@ -0,0 +1,590 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bfs_brute_force'
4
+
5
+ # Puzzle:
6
+ #
7
+ # Swap black and white bishops, following standard chess movement
8
+ # rules, except that bishops may not move to a square that would allow
9
+ # them to be captured by an enemy bishop (they may not put themselves
10
+ # in "check").
11
+ #
12
+ # This is the "four bishops" puzzle from an old video game, The 7th Guest.
13
+ #
14
+ # Initial Board layout:
15
+ #
16
+ # +----+----+----+----+----+
17
+ # 4 | BB | | | | WB |
18
+ # +----+----+----+----+----+
19
+ # 3 | BB | | | | WB |
20
+ # +----+----+----+----+----+
21
+ # 2 | BB | | | | WB |
22
+ # +----+----+----+----+----+
23
+ # 1 | BB | | | | WB |
24
+ # +----+----+----+----+----+
25
+ # a b c d e
26
+ #
27
+ # BB = Black Bishop
28
+ # WB = White Bishop
29
+
30
+ class FourBishopsState < BfsBruteForce::State
31
+ # Legal moves: from_position => [to_position, ...]
32
+ @@moves = {
33
+ :a1 => [:b2, :c3, :d4],
34
+ :a2 => [:b1, :b3, :c4],
35
+ :a3 => [:b2, :b4, :c1],
36
+ :a4 => [:b3, :c2, :d1],
37
+ :b1 => [:a2, :c2, :d3, :e4],
38
+ :b2 => [:a1, :a3, :c1, :c3, :d4],
39
+ :b3 => [:a2, :a4, :c2, :c4, :d1],
40
+ :b4 => [:a3, :c3, :d2, :e1],
41
+ :c1 => [:a3, :b2, :d2, :e3],
42
+ :c2 => [:a4, :b1, :b3, :d1, :d3, :e4],
43
+ :c3 => [:a1, :b2, :b4, :d2, :d4, :e1],
44
+ :c4 => [:a2, :b3, :d3, :e2],
45
+ :d1 => [:a4, :b3, :c2, :e2],
46
+ :d2 => [:b4, :c1, :c3, :e1, :e3],
47
+ :d3 => [:b1, :c2, :c4, :c4, :e2],
48
+ :d4 => [:a1, :b2, :c3, :e3],
49
+ :e1 => [:b4, :c3, :d2],
50
+ :e2 => [:c4, :d1, :d3],
51
+ :e3 => [:c1, :d2, :d4],
52
+ :e4 => [:b1, :c2, :d3]
53
+ }
54
+
55
+ def initialize(bishops = nil)
56
+ # State of the board: position => bishop
57
+ @bishops = bishops || {
58
+ :a1 => :BB, :a2 => :BB, :a3 => :BB, :a4 => :BB,
59
+ :e1 => :WB, :e2 => :WB, :e3 => :WB, :e4 => :WB
60
+ }
61
+ end
62
+
63
+ # (see BfsBruteForce::State#solved)
64
+ def solved?
65
+ @bishops == {
66
+ :a1 => :WB, :a2 => :WB, :a3 => :WB, :a4 => :WB,
67
+ :e1 => :BB, :e2 => :BB, :e3 => :BB, :e4 => :BB
68
+ }
69
+ end
70
+
71
+ # Yield all not previously seen states from the current state
72
+ # (see BfsBruteForce::State#already_seen)
73
+ def next_states(already_seen)
74
+ @bishops.each do |from, bishop|
75
+ enemy = bishop == :WB ? :BB : :WB
76
+ illegal = @bishops.select {|_, b| b == enemy}.flat_map {|p, _| @@moves[p]}
77
+
78
+ @@moves[from].reject do |to|
79
+ # Skip illegal positions
80
+ @bishops[to] or illegal.include?(to)
81
+ end.each do |to|
82
+ new_bishops = @bishops.merge(to => bishop)
83
+ new_bishops.delete from
84
+
85
+ if already_seen.add?(new_bishops)
86
+ state = FourBishopsState.new new_bishops
87
+ move = "Move #{bishop} from #{from} to #{to}\n#{state}"
88
+ yield move, state
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ def to_s
95
+ fmt = %Q{
96
+ +----+----+----+----+----+
97
+ 4 | %s | %s | %s | %s | %s |
98
+ +----+----+----+----+----+
99
+ 3 | %s | %s | %s | %s | %s |
100
+ +----+----+----+----+----+
101
+ 2 | %s | %s | %s | %s | %s |
102
+ +----+----+----+----+----+
103
+ 1 | %s | %s | %s | %s | %s |
104
+ +----+----+----+----+----+
105
+ a b c d e
106
+ }
107
+ fmt % [
108
+ :a4, :b4, :c4, :d4, :e4,
109
+ :a3, :b3, :c3, :d3, :e3,
110
+ :a2, :b2, :c2, :d2, :e2,
111
+ :a1, :b1, :c1, :d1, :e1
112
+ ].map {|index| @bishops[index] || ' '}
113
+ end
114
+ end
115
+
116
+ solver = BfsBruteForce::Solver.new
117
+ moves = solver.solve(FourBishopsState.new).moves
118
+
119
+ puts moves
120
+
121
+ # Running this code will produce the following output:
122
+ #
123
+ # Move BB from a2 to b3
124
+ #
125
+ # +----+----+----+----+----+
126
+ # 4 | BB | | | | WB |
127
+ # +----+----+----+----+----+
128
+ # 3 | BB | BB | | | WB |
129
+ # +----+----+----+----+----+
130
+ # 2 | | | | | WB |
131
+ # +----+----+----+----+----+
132
+ # 1 | BB | | | | WB |
133
+ # +----+----+----+----+----+
134
+ # a b c d e
135
+ #
136
+ # Move BB from a3 to b2
137
+ #
138
+ # +----+----+----+----+----+
139
+ # 4 | BB | | | | WB |
140
+ # +----+----+----+----+----+
141
+ # 3 | | BB | | | WB |
142
+ # +----+----+----+----+----+
143
+ # 2 | | BB | | | WB |
144
+ # +----+----+----+----+----+
145
+ # 1 | BB | | | | WB |
146
+ # +----+----+----+----+----+
147
+ # a b c d e
148
+ #
149
+ # Move WB from e1 to b4
150
+ #
151
+ # +----+----+----+----+----+
152
+ # 4 | BB | WB | | | WB |
153
+ # +----+----+----+----+----+
154
+ # 3 | | BB | | | WB |
155
+ # +----+----+----+----+----+
156
+ # 2 | | BB | | | WB |
157
+ # +----+----+----+----+----+
158
+ # 1 | BB | | | | |
159
+ # +----+----+----+----+----+
160
+ # a b c d e
161
+ #
162
+ # Move WB from e2 to d3
163
+ #
164
+ # +----+----+----+----+----+
165
+ # 4 | BB | WB | | | WB |
166
+ # +----+----+----+----+----+
167
+ # 3 | | BB | | WB | WB |
168
+ # +----+----+----+----+----+
169
+ # 2 | | BB | | | |
170
+ # +----+----+----+----+----+
171
+ # 1 | BB | | | | |
172
+ # +----+----+----+----+----+
173
+ # a b c d e
174
+ #
175
+ # Move BB from a4 to d1
176
+ #
177
+ # +----+----+----+----+----+
178
+ # 4 | | WB | | | WB |
179
+ # +----+----+----+----+----+
180
+ # 3 | | BB | | WB | WB |
181
+ # +----+----+----+----+----+
182
+ # 2 | | BB | | | |
183
+ # +----+----+----+----+----+
184
+ # 1 | BB | | | BB | |
185
+ # +----+----+----+----+----+
186
+ # a b c d e
187
+ #
188
+ # Move WB from e3 to d2
189
+ #
190
+ # +----+----+----+----+----+
191
+ # 4 | | WB | | | WB |
192
+ # +----+----+----+----+----+
193
+ # 3 | | BB | | WB | |
194
+ # +----+----+----+----+----+
195
+ # 2 | | BB | | WB | |
196
+ # +----+----+----+----+----+
197
+ # 1 | BB | | | BB | |
198
+ # +----+----+----+----+----+
199
+ # a b c d e
200
+ #
201
+ # Move BB from b2 to d4
202
+ #
203
+ # +----+----+----+----+----+
204
+ # 4 | | WB | | BB | WB |
205
+ # +----+----+----+----+----+
206
+ # 3 | | BB | | WB | |
207
+ # +----+----+----+----+----+
208
+ # 2 | | | | WB | |
209
+ # +----+----+----+----+----+
210
+ # 1 | BB | | | BB | |
211
+ # +----+----+----+----+----+
212
+ # a b c d e
213
+ #
214
+ # Move WB from b4 to a3
215
+ #
216
+ # +----+----+----+----+----+
217
+ # 4 | | | | BB | WB |
218
+ # +----+----+----+----+----+
219
+ # 3 | WB | BB | | WB | |
220
+ # +----+----+----+----+----+
221
+ # 2 | | | | WB | |
222
+ # +----+----+----+----+----+
223
+ # 1 | BB | | | BB | |
224
+ # +----+----+----+----+----+
225
+ # a b c d e
226
+ #
227
+ # Move WB from d3 to b1
228
+ #
229
+ # +----+----+----+----+----+
230
+ # 4 | | | | BB | WB |
231
+ # +----+----+----+----+----+
232
+ # 3 | WB | BB | | | |
233
+ # +----+----+----+----+----+
234
+ # 2 | | | | WB | |
235
+ # +----+----+----+----+----+
236
+ # 1 | BB | WB | | BB | |
237
+ # +----+----+----+----+----+
238
+ # a b c d e
239
+ #
240
+ # Move BB from b3 to c4
241
+ #
242
+ # +----+----+----+----+----+
243
+ # 4 | | | BB | BB | WB |
244
+ # +----+----+----+----+----+
245
+ # 3 | WB | | | | |
246
+ # +----+----+----+----+----+
247
+ # 2 | | | | WB | |
248
+ # +----+----+----+----+----+
249
+ # 1 | BB | WB | | BB | |
250
+ # +----+----+----+----+----+
251
+ # a b c d e
252
+ #
253
+ # Move BB from d1 to e2
254
+ #
255
+ # +----+----+----+----+----+
256
+ # 4 | | | BB | BB | WB |
257
+ # +----+----+----+----+----+
258
+ # 3 | WB | | | | |
259
+ # +----+----+----+----+----+
260
+ # 2 | | | | WB | BB |
261
+ # +----+----+----+----+----+
262
+ # 1 | BB | WB | | | |
263
+ # +----+----+----+----+----+
264
+ # a b c d e
265
+ #
266
+ # Move WB from e4 to c2
267
+ #
268
+ # +----+----+----+----+----+
269
+ # 4 | | | BB | BB | |
270
+ # +----+----+----+----+----+
271
+ # 3 | WB | | | | |
272
+ # +----+----+----+----+----+
273
+ # 2 | | | WB | WB | BB |
274
+ # +----+----+----+----+----+
275
+ # 1 | BB | WB | | | |
276
+ # +----+----+----+----+----+
277
+ # a b c d e
278
+ #
279
+ # Move WB from d2 to c1
280
+ #
281
+ # +----+----+----+----+----+
282
+ # 4 | | | BB | BB | |
283
+ # +----+----+----+----+----+
284
+ # 3 | WB | | | | |
285
+ # +----+----+----+----+----+
286
+ # 2 | | | WB | | BB |
287
+ # +----+----+----+----+----+
288
+ # 1 | BB | WB | WB | | |
289
+ # +----+----+----+----+----+
290
+ # a b c d e
291
+ #
292
+ # Move BB from a1 to c3
293
+ #
294
+ # +----+----+----+----+----+
295
+ # 4 | | | BB | BB | |
296
+ # +----+----+----+----+----+
297
+ # 3 | WB | | BB | | |
298
+ # +----+----+----+----+----+
299
+ # 2 | | | WB | | BB |
300
+ # +----+----+----+----+----+
301
+ # 1 | | WB | WB | | |
302
+ # +----+----+----+----+----+
303
+ # a b c d e
304
+ #
305
+ # Move WB from c2 to a4
306
+ #
307
+ # +----+----+----+----+----+
308
+ # 4 | WB | | BB | BB | |
309
+ # +----+----+----+----+----+
310
+ # 3 | WB | | BB | | |
311
+ # +----+----+----+----+----+
312
+ # 2 | | | | | BB |
313
+ # +----+----+----+----+----+
314
+ # 1 | | WB | WB | | |
315
+ # +----+----+----+----+----+
316
+ # a b c d e
317
+ #
318
+ # Move WB from b1 to c2
319
+ #
320
+ # +----+----+----+----+----+
321
+ # 4 | WB | | BB | BB | |
322
+ # +----+----+----+----+----+
323
+ # 3 | WB | | BB | | |
324
+ # +----+----+----+----+----+
325
+ # 2 | | | WB | | BB |
326
+ # +----+----+----+----+----+
327
+ # 1 | | | WB | | |
328
+ # +----+----+----+----+----+
329
+ # a b c d e
330
+ #
331
+ # Move BB from c4 to a2
332
+ #
333
+ # +----+----+----+----+----+
334
+ # 4 | WB | | | BB | |
335
+ # +----+----+----+----+----+
336
+ # 3 | WB | | BB | | |
337
+ # +----+----+----+----+----+
338
+ # 2 | BB | | WB | | BB |
339
+ # +----+----+----+----+----+
340
+ # 1 | | | WB | | |
341
+ # +----+----+----+----+----+
342
+ # a b c d e
343
+ #
344
+ # Move BB from e2 to c4
345
+ #
346
+ # +----+----+----+----+----+
347
+ # 4 | WB | | BB | BB | |
348
+ # +----+----+----+----+----+
349
+ # 3 | WB | | BB | | |
350
+ # +----+----+----+----+----+
351
+ # 2 | BB | | WB | | |
352
+ # +----+----+----+----+----+
353
+ # 1 | | | WB | | |
354
+ # +----+----+----+----+----+
355
+ # a b c d e
356
+ #
357
+ # Move BB from c3 to e1
358
+ #
359
+ # +----+----+----+----+----+
360
+ # 4 | WB | | BB | BB | |
361
+ # +----+----+----+----+----+
362
+ # 3 | WB | | | | |
363
+ # +----+----+----+----+----+
364
+ # 2 | BB | | WB | | |
365
+ # +----+----+----+----+----+
366
+ # 1 | | | WB | | BB |
367
+ # +----+----+----+----+----+
368
+ # a b c d e
369
+ #
370
+ # Move BB from d4 to c3
371
+ #
372
+ # +----+----+----+----+----+
373
+ # 4 | WB | | BB | | |
374
+ # +----+----+----+----+----+
375
+ # 3 | WB | | BB | | |
376
+ # +----+----+----+----+----+
377
+ # 2 | BB | | WB | | |
378
+ # +----+----+----+----+----+
379
+ # 1 | | | WB | | BB |
380
+ # +----+----+----+----+----+
381
+ # a b c d e
382
+ #
383
+ # Move WB from c1 to e3
384
+ #
385
+ # +----+----+----+----+----+
386
+ # 4 | WB | | BB | | |
387
+ # +----+----+----+----+----+
388
+ # 3 | WB | | BB | | WB |
389
+ # +----+----+----+----+----+
390
+ # 2 | BB | | WB | | |
391
+ # +----+----+----+----+----+
392
+ # 1 | | | | | BB |
393
+ # +----+----+----+----+----+
394
+ # a b c d e
395
+ #
396
+ # Move WB from a3 to c1
397
+ #
398
+ # +----+----+----+----+----+
399
+ # 4 | WB | | BB | | |
400
+ # +----+----+----+----+----+
401
+ # 3 | | | BB | | WB |
402
+ # +----+----+----+----+----+
403
+ # 2 | BB | | WB | | |
404
+ # +----+----+----+----+----+
405
+ # 1 | | | WB | | BB |
406
+ # +----+----+----+----+----+
407
+ # a b c d e
408
+ #
409
+ # Move WB from c2 to d1
410
+ #
411
+ # +----+----+----+----+----+
412
+ # 4 | WB | | BB | | |
413
+ # +----+----+----+----+----+
414
+ # 3 | | | BB | | WB |
415
+ # +----+----+----+----+----+
416
+ # 2 | BB | | | | |
417
+ # +----+----+----+----+----+
418
+ # 1 | | | WB | WB | BB |
419
+ # +----+----+----+----+----+
420
+ # a b c d e
421
+ #
422
+ # Move BB from a2 to b1
423
+ #
424
+ # +----+----+----+----+----+
425
+ # 4 | WB | | BB | | |
426
+ # +----+----+----+----+----+
427
+ # 3 | | | BB | | WB |
428
+ # +----+----+----+----+----+
429
+ # 2 | | | | | |
430
+ # +----+----+----+----+----+
431
+ # 1 | | BB | WB | WB | BB |
432
+ # +----+----+----+----+----+
433
+ # a b c d e
434
+ #
435
+ # Move BB from c4 to d3
436
+ #
437
+ # +----+----+----+----+----+
438
+ # 4 | WB | | | | |
439
+ # +----+----+----+----+----+
440
+ # 3 | | | BB | BB | WB |
441
+ # +----+----+----+----+----+
442
+ # 2 | | | | | |
443
+ # +----+----+----+----+----+
444
+ # 1 | | BB | WB | WB | BB |
445
+ # +----+----+----+----+----+
446
+ # a b c d e
447
+ #
448
+ # Move BB from c3 to b4
449
+ #
450
+ # +----+----+----+----+----+
451
+ # 4 | WB | BB | | | |
452
+ # +----+----+----+----+----+
453
+ # 3 | | | | BB | WB |
454
+ # +----+----+----+----+----+
455
+ # 2 | | | | | |
456
+ # +----+----+----+----+----+
457
+ # 1 | | BB | WB | WB | BB |
458
+ # +----+----+----+----+----+
459
+ # a b c d e
460
+ #
461
+ # Move WB from e3 to d4
462
+ #
463
+ # +----+----+----+----+----+
464
+ # 4 | WB | BB | | WB | |
465
+ # +----+----+----+----+----+
466
+ # 3 | | | | BB | |
467
+ # +----+----+----+----+----+
468
+ # 2 | | | | | |
469
+ # +----+----+----+----+----+
470
+ # 1 | | BB | WB | WB | BB |
471
+ # +----+----+----+----+----+
472
+ # a b c d e
473
+ #
474
+ # Move WB from c1 to b2
475
+ #
476
+ # +----+----+----+----+----+
477
+ # 4 | WB | BB | | WB | |
478
+ # +----+----+----+----+----+
479
+ # 3 | | | | BB | |
480
+ # +----+----+----+----+----+
481
+ # 2 | | WB | | | |
482
+ # +----+----+----+----+----+
483
+ # 1 | | BB | | WB | BB |
484
+ # +----+----+----+----+----+
485
+ # a b c d e
486
+ #
487
+ # Move WB from d1 to b3
488
+ #
489
+ # +----+----+----+----+----+
490
+ # 4 | WB | BB | | WB | |
491
+ # +----+----+----+----+----+
492
+ # 3 | | WB | | BB | |
493
+ # +----+----+----+----+----+
494
+ # 2 | | WB | | | |
495
+ # +----+----+----+----+----+
496
+ # 1 | | BB | | | BB |
497
+ # +----+----+----+----+----+
498
+ # a b c d e
499
+ #
500
+ # Move BB from b1 to e4
501
+ #
502
+ # +----+----+----+----+----+
503
+ # 4 | WB | BB | | WB | BB |
504
+ # +----+----+----+----+----+
505
+ # 3 | | WB | | BB | |
506
+ # +----+----+----+----+----+
507
+ # 2 | | WB | | | |
508
+ # +----+----+----+----+----+
509
+ # 1 | | | | | BB |
510
+ # +----+----+----+----+----+
511
+ # a b c d e
512
+ #
513
+ # Move BB from d3 to e2
514
+ #
515
+ # +----+----+----+----+----+
516
+ # 4 | WB | BB | | WB | BB |
517
+ # +----+----+----+----+----+
518
+ # 3 | | WB | | | |
519
+ # +----+----+----+----+----+
520
+ # 2 | | WB | | | BB |
521
+ # +----+----+----+----+----+
522
+ # 1 | | | | | BB |
523
+ # +----+----+----+----+----+
524
+ # a b c d e
525
+ #
526
+ # Move BB from b4 to d2
527
+ #
528
+ # +----+----+----+----+----+
529
+ # 4 | WB | | | WB | BB |
530
+ # +----+----+----+----+----+
531
+ # 3 | | WB | | | |
532
+ # +----+----+----+----+----+
533
+ # 2 | | WB | | BB | BB |
534
+ # +----+----+----+----+----+
535
+ # 1 | | | | | BB |
536
+ # +----+----+----+----+----+
537
+ # a b c d e
538
+ #
539
+ # Move WB from d4 to a1
540
+ #
541
+ # +----+----+----+----+----+
542
+ # 4 | WB | | | | BB |
543
+ # +----+----+----+----+----+
544
+ # 3 | | WB | | | |
545
+ # +----+----+----+----+----+
546
+ # 2 | | WB | | BB | BB |
547
+ # +----+----+----+----+----+
548
+ # 1 | WB | | | | BB |
549
+ # +----+----+----+----+----+
550
+ # a b c d e
551
+ #
552
+ # Move WB from b2 to a3
553
+ #
554
+ # +----+----+----+----+----+
555
+ # 4 | WB | | | | BB |
556
+ # +----+----+----+----+----+
557
+ # 3 | WB | WB | | | |
558
+ # +----+----+----+----+----+
559
+ # 2 | | | | BB | BB |
560
+ # +----+----+----+----+----+
561
+ # 1 | WB | | | | BB |
562
+ # +----+----+----+----+----+
563
+ # a b c d e
564
+ #
565
+ # Move WB from b3 to a2
566
+ #
567
+ # +----+----+----+----+----+
568
+ # 4 | WB | | | | BB |
569
+ # +----+----+----+----+----+
570
+ # 3 | WB | | | | |
571
+ # +----+----+----+----+----+
572
+ # 2 | WB | | | BB | BB |
573
+ # +----+----+----+----+----+
574
+ # 1 | WB | | | | BB |
575
+ # +----+----+----+----+----+
576
+ # a b c d e
577
+ #
578
+ # Move BB from d2 to e3
579
+ #
580
+ # +----+----+----+----+----+
581
+ # 4 | WB | | | | BB |
582
+ # +----+----+----+----+----+
583
+ # 3 | WB | | | | BB |
584
+ # +----+----+----+----+----+
585
+ # 2 | WB | | | | BB |
586
+ # +----+----+----+----+----+
587
+ # 1 | WB | | | | BB |
588
+ # +----+----+----+----+----+
589
+ # a b c d e
590
+ #