AI Puzzle Framework Sliding Box Puzzle Protocol Document Brian Shaver April 3, 2005
Sliding Box Puzzle Protocol Document Page 2 of 7 Table of Contents Table of Contents...2 Introduction...3 Puzzle Description... 3 Rules... 3 Board State...4 Flags... 4 Representation... 4 Representation Tips... 5 Sample Board Layout File... 5 Module Requirements...6 Puzzle Number... 6 Puzzle Module... 6 Board Module... 6 Player Module... 6 Appendix A Box Configurations...7
Sliding Box Puzzle Protocol Document Page 3 of 7 Introduction Puzzle Description A sliding box puzzle consists of a system of open boxes, which can be moved by pushing from the inside. There are two sizes of boxes small and large, in addition to the small moving piece. The goal of the sliding box puzzle is to push the boxes in order to place the small red box inside of the large blue box. Rules 1. A box is a three-sided square, which comes in 2 (two) different sizes, small and large, and 3 (three) different colors, black, blue, and red. 2. The mover piece is a very small black square which can fit into both small and large boxes; there is only one mover piece per puzzle. 3. The puzzle board is arranged in a grid pattern, surrounded by impenetrable, immovable walls. 4. Each square on the grid will contain one of the following at any given time: A blank space containing no boxes or the mover piece A immovable wall space The mover piece, only The mover piece inside of a small box The mover piece inside of a large box The mover piece inside of a small box, which is itself inside of a large box 5. Every puzzle will have exactly 1 (one) small red box, and exactly 1 (one) large blue box. 6. A move consists of the displacement of the mover piece, possibly pushing a small and/or large box from one grid square to another square which is immediately adjacent. 7. Moves may only be made to horizontally or vertically adjacent grid squares; no diagonal moves are allowed. 8. Boxes may only be pushed by the mover piece, and only from the inside. 9. The mover piece may only enter or exit a box through the open side. 10. 1 (one) small box can fit inside of 1 (one) large box, and the mover piece may push them both at the same time. 11. When the small red box is placed within the large blue box, the puzzle ends. 12. A solution to the puzzle is defined as a series of moves which ends with the placing of the small red box inside of the large blue box. 13. Every puzzle that has a solution will have an optimal solution such that the total number of moves required for the solution is the minimum of all total moves for any possible solution to the given puzzle. 14. The overall goal for the player is to find the optimal solution to the puzzle. 15. It is possible to lose the puzzle if the small red box is no longer capable of being placed within the large blue box.
Sliding Box Puzzle Protocol Document Page 4 of 7 Board State Flags The following flags are used by the Sliding Box Puzzle when configuring the board state: Flag USE_TIME USE_MOVES LIMIT_NONE Representation Purpose Count time for the puzzle Count moves for the puzzle Do not limit the puzzle based on time or moves See Appendix A for examples of box configurations referenced in this table (all references are from left to right, unless otherwise noted). The Sliding Box Puzzle board state is represented internally and in.puz layout files as follows (which corresponding ASCII values in base 10): Character ASCII Value Meaning Space 32 Unoccupied grid square # 35 Filled in, blocked square. 46 Mover piece, alone 0 1 2 3 [48,51] Large black boxes in Row I of example table, respectively 4 5 6 7 [52,55] Large blue boxes Row I 8 9 : ; [56,59] Small black boxes Row III < = >? [60,63] Small red boxes Row III @ A B C [64,67] Large black boxes Row II [D,G] [68,71] Large blue boxes Row II [H,K] [72,75] Small black boxes Row IV [L,O] [76,79] Small red boxes Row IV [P,S] [80,83] Large black/small black boxes Row V [T,W] [84,87] Large black/small red boxes Row V X Y Z [ [88,91] Large blue/small black boxes Row V Note: There are no large blue/small red combinations possible for the Row V configurations ` a b c [96,99] Large black/small black boxes Row VI [d,g] [100,103] Large black/small black boxes Row VII [h,k] [104,107] Large black/small black boxes Row VIII [l,o] [108,111] Large black/small black boxes Row IX [p,s] [112,115] Large black/small red boxes Row VI [t,w] [116,119] Large black/small red boxes Row VII
Sliding Box Puzzle Protocol Document Page 5 of 7 x y z { [120,123] Large black/small red boxes Row VIII } ~ [124,127] Large black/small red boxes Row IX Ç ü é â [128,131] Large blue/small black boxes Row VI ä à å ç [132,135] Large blue/small black boxes Row VII ê ë è ï [136,139] Large blue/small black boxes Row VIII î ì Ä Å [140,143] Large blue/small black boxes Row IX É æ Æ ô [144,147] Large blue/small red boxes Row VI (winning condition) ö ò û ù [148,151] Large blue/small red boxes Row VII (winning condition) ÿ Ö Ü [152,155] Large blue/small red boxes Row VIII (winning condition) ƒ [156,159] Large blue/small red boxes Row IX (winning condition) Representation Tips At first, the characters used to represent objects on the board may seem to be non-intuitive, and confusing. However, the characters are not as important as the ASCII values that are used to represent those characters. Several quick mathematical operations on these values can dramatically simplify the computation necessary to determine what piece is where. 1. The mover piece will always be located at a space with value 46, 64-79, or 96-159. 2. Empty boxes are numbered from 48 through 63. A box with only the mover piece inside of it is can be found by taking the value of the empty box and adding 16. 3. The opening of the outermost box will always be the remainder of the ASCII value of the space when divided by four (modulus operator: A%4). If the resulting value is: 0 opens up, 1 opens right, 2 opens down, 3 opens left. (Clockwise motion) 4. For spaces with a value greater than or equal to 96 (when 2 boxes and the mover piece are together), the opening of the outermost box may be found as above, and the opening of the innermost box can be found by taking the remainder of the ASCII value when divided by 16, and doing an integer division (no decimal) with 4. (int((a%16)/4)) The resulting value represents, in a clockwise motion (as above) where the opening is, starting at the top. 5. The opening of the innermost box when there are 2 boxes, but no mover on a space is always the same direction that the outermost box opens (which can be found above). When using Notepad on the Windows operating system to create board layout files, holding down the Alt key while typing in the ASCII value of the character into the number pad then releasing the Alt key will produce the desired character. Sample Board Layout File Following the standards for board layout files (.puz files) defined in the Module Developer Guide, the following is a sample board layout file for the Sliding Box Puzzle: 3 4 4
Sliding Box Puzzle Protocol Document Page 6 of 7 0 0 0 0 0 0.6 #= :# 0 Module Requirements Puzzle Number The Sliding Box Puzzle has a puzzle identification number (puzid) of 3 (three), which must be set in the LibraryInfo for each of the modules, and for the board layout files intended for use with the Sliding Box Puzzle. Use of any other number will cause the given module or layout file to not work correctly with the given puzzle, and may also conflict with other, previously defined puzzle ID numbers. Puzzle Module For the Sliding Box Puzzle, the puzzle module will not contain an initial state, but rather it will be loaded from a.puz board layout file. The board state is fully visible to the player at all times, so the full board state should always be returned by the module. Board Module The board module must be sure to display the special boxes (the large blue, and small red boxes) in their respective colors, as well as displaying the regular boxes in black. Additionally a grid should be displayed around all the board pieces, in order to indicate to the user the exact location of each piece in relation to the other pieces on the board. The board module should also be able to handle keyboard movements from the user (using arrow keys to indicate direction of movement), and mouse movements when the user clicks on the space to which the Mover piece should be moved Player Module No special requirements are necessary for the player module in the Sliding Box Puzzle. However it is important to note that there are losing states in this puzzle, and thus, if a bad move is played, it is not always possible to revert to the previous board state by reversing the move.
(6) (7) (8) VI (21)(2) N/A* (23) (24) I (9) (10) (1)(12) VI (25)(26) (27) N/A* (28) I Sliding Box Puzzle Protocol Document Page 7 of 7 IV (13)(14) (15)(16) VIN/A* (29)(30) (31) (32) (3)(34) (35) (36) V (17)(18) (19)(20) IX N/A* *Theseconfigurationsareimposible, buthevalueistil representationtabletopreserve symetry. reservedinthe Appendix A Box Configurations (1) (2) (3) (4) I WhenusingNotepadontheWindowsoperatingsyste