Professional Documents
Culture Documents
Sokoban en
Sokoban en
0 1 2 3 4 5 6 7
0
1
using wall((X1,Y1),(X2,Y2)), crate(Id,X,Y) and storage(X,Y) prolog
terms. These terms identify the coordinates of respectively walls, boxes and
storage locations, where (0,0) corresponds to the top left corner. In the case
of crate/3 and storage/2 terms, the X and Y directly indicate the object’s
coordinates, for wall/2 terms the coordinates of the end points are given.
Because walls always run strictly horizontal or strictly vertical, either the
X or the Y coordinate of both coordinates is the same. Furthermore you
may assume that the first coordinate of the two is always the left uppermost
coordinate. This way, Figure 2 can be described as:
0 1 2 3 4 5 6
0
1
2
3
4
5
6
sokoban (7 ,7 , (1 ,1) , [ wall ((0 ,0) ,(6 ,0) ) , wall ((6 ,0)
,(6 ,6) ) , wall ((0 ,6) ,(6 ,6) ) , wall ((0 ,0) ,(0 ,6) ) ,
wall ((3 ,0) ,(3 ,2) ) , wall ((3 ,4) ,(3 ,6) ) , crate
(1 ,3 ,3) , storage (1 ,3) ])
Fabian likes playing Sokoban games so much that he has written his
own solver. Now he asks us to check his solver for mistakes. Sadly, Fabian’s
solver only reports the order in which the boxes need to be pushed, not in
which direction or how far!
2
setup (as given by Sokoban). The player can only move horizontally and
vertically along free squares (i.e. not containing a box or a wall, storage
locations are fine as long as they do not contain a box), without pushing
any boxes. Of course, he is allowed not to move at all.
Remark: Make sure that every possible position is found exactly once,
as shown in the query above. If you do not succeed in this, then add the
following predicate definition:
reachable_once (S , Loc ) : -
findall (E , reachable (S , E ) , Locs ) ,
list_to_set ( Locs , DistLocs ) ,
member ( Loc , DistLocs ) .
In that case, for the remainder of your program, only use reachable_once.
• The player can only push a box when he’s located right next to it. If
he’s standing left of a box, he can only push it to the right, etc.
3
% The player is not standing next to box 1
? - Sokoban = sokoban (7 ,7 , (1 ,1) , [ wall ((0 ,0) ,(6 ,0) ) ,
wall ((6 ,0) ,(6 ,6) ) , wall ((0 ,6) ,(6 ,6) ) , wall ((0 ,0)
,(0 ,6) ) , wall ((3 ,0) ,(3 ,2) ) , wall ((3 ,4) ,(3 ,6) ) ,
crate (1 ,3 ,3) , storage (1 ,3) ] ,
possible ( Sokoban , 1 , Location ) .
false .
4
% These examples use the sokoban from Fig . 1.
% Solution in Table 1.
? - check ( sokoban (8 , 9 , (2 ,2) , [ wall ((2 ,0) , (6 ,0) ) ,
wall ((6 ,1) , (6 ,5) ) , wall ((7 ,5) ,(7 ,8) ) , wall ((0 ,8)
, (7 ,8) ) , wall ((0 , 1) , (0 ,8) ) , wall ((1 ,1) ,(2 ,1) ) ,
wall ((1 ,3) ,(2 ,3) ) , wall ((2 ,4) ,(3 ,4) ) , wall ((2 ,5)
,(2 ,5) ) , crate (1 ,3 ,2) , crate (2 ,4 ,3) , crate (3 ,4 ,4)
, crate (4 ,1 ,6) , crate (5 ,3 ,6) , crate (6 ,4 ,6) , crate
(7 ,5 ,6) , storage (1 ,2) , storage (5 ,3) , storage (1 ,4)
, storage (4 ,5) , storage (3 ,6) , storage (6 ,6) ,
storage (4 ,7) ]) , [1 ,6 ,7 ,1 ,2 ,3 ,5 ,4 ,5]) .
true .
false .
5
Table 1: Solution for Figure 1.