README (6320B)
1 24apr12abu 2 (c) Software Lab. Alexander Burger 3 4 5 PicoLisp Demo Games 6 =================== 7 8 This directory contains a few simple games. They are neither especially 9 interesting, nor powerful, but may be useful as programming examples. 10 11 For a global PicoLisp installation (see the INSTALL file), either supply a full 12 path to "/usr/share/picolisp/games/<file>.l" instead of just "games/<file>.l" in 13 the commands below, or change the working directory to "/usr/share/picolisp/". 14 15 16 'mine' is a simplified version of the minesweeper game. You can start it as: 17 18 $ pil games/mine.l -main -go + 19 20 It will display a 12-by-12 field with 24 (default) hidden mines. You can move 21 around using the standard 'vi'-keys 'j' (down), 'k' (up), 'l' (right) and 'h' 22 (left). 23 24 Hit ENTER or SPACE to uncover a field, and ESC to terminate the game. In the 25 latter case (of if a mine exploded), you'll get the PicoLisp prompt. Then you 26 can continue the game with 27 28 : (go) 29 30 possibly after re-initializing it with 31 32 : (main) 33 34 or exit the PicoLisp interpreter with ENTER. 35 36 37 38 'nim' and 'ttt' are only testbeds for the general 'game' alpha-beta search 39 function (normally, these games are better implemented by directly exploring 40 their underlying principles and strategies). 41 42 Start 'nim' as 43 44 $ pil games/nim.l + 45 46 and then find the optimal move path for, let's say, three heaps of four matches 47 each: 48 49 : (nim 4 4 4) 50 -> (-100 ((1 . 4) 1 . -4) ((2 . 4) 2 . -4) ((3 . 4) 3 . -4)) 51 52 This is a winning position (a minimal cost of -100), with three moves (in the 53 CARs of the move list: Take 4 from heap 1, then 4 from heap 2, and finally 4 54 from heap 3). 55 56 57 58 To play Tic-Tac-Toe, enter 59 60 $ pil games/ttt.l -main + 61 62 A three-by-three board is displayed. Enter your moves with the 'go' function: 63 64 : (go a 1) 65 +---+---+---+ 66 3 | | | | 67 +---+---+---+ 68 2 | | | | 69 +---+---+---+ 70 1 | T | | | 71 +---+---+---+ 72 a b c 73 74 Your positions are marked with 'T', the computer's with '0'. 75 76 77 78 The 'chess' game is minimalistic (447 lines of code). Nevertheless, it plays 79 some slow - though correct - chess. Start it as: 80 81 $ pil games/chess.l -main + 82 +---+---+---+---+---+---+---+---+ 83 8 |<R>|<N>|<B>|<Q>|<K>|<B>|<N>|<R>| 84 +---+---+---+---+---+---+---+---+ 85 7 |<P>|<P>|<P>|<P>|<P>|<P>|<P>|<P>| 86 +---+---+---+---+---+---+---+---+ 87 6 | | - | | - | | - | | - | 88 +---+---+---+---+---+---+---+---+ 89 5 | - | | - | | - | | - | | 90 +---+---+---+---+---+---+---+---+ 91 4 | | - | | - | | - | | - | 92 +---+---+---+---+---+---+---+---+ 93 3 | - | | - | | - | | - | | 94 +---+---+---+---+---+---+---+---+ 95 2 | P | P | P | P | P | P | P | P | 96 +---+---+---+---+---+---+---+---+ 97 1 | R | N | B | Q | K | B | N | R | 98 +---+---+---+---+---+---+---+---+ 99 a b c d e f g h 100 101 The pieces are indicated by the letters 'K'ing, 'Q'ueen, 'R'ook, 'B'ishop, 102 k'N'ight and 'P'awn, with black pieces in angular brackets. 103 104 105 Alternatively, you can also run it through XBoard (in the X Window System): 106 107 $ xboard -fcp games/xchess 108 109 110 Without XBoard, you may enter your moves with the field names (in lower case) 111 for the "from" and "to" positions: 112 113 : (go e2 e4) 114 115 Castling may be entered by just specifying the king's move: 116 117 : (go e1 g1) 118 119 To promote a pawn to some piece other than a queen, you can specify a class: 120 121 : (go h7 h8 +Knight) 122 123 To undo one or several moves, enter 124 125 : (go -) 126 127 and to redo them 128 129 : (go +) 130 131 To switch sides (and have the computer play against itself), call 'go' without 132 arguments: 133 134 : (go) 135 136 The initial board position can be restored with 137 138 : (main) 139 140 The global variable '*Depth' holds the maximal depth of the alpha-beta tree 141 search. It defaults to 5. You may change it to some smaller value for a faster 142 response, or to a larger value for a deeper search: 143 144 : (setq *Depth 7) 145 146 The same effect can be achieved by passing the desired depth as the first 147 argument to 'main': 148 149 : (main 7) 150 151 The second (optional) argument to 'main' is your color ('NIL' for white and 'T' 152 for black). 153 154 To setup some given board position, call 'main' with a list of triples, with 155 each describing: 156 157 1. The field 158 2. The piece's classes 159 3. An optional flag to indicate that the piece did not move yet 160 161 : (main 5 NIL 162 (quote 163 (a2 (+White +Pawn) T) 164 (b1 (+White +King)) 165 (d4 (+Black +King)) ) ) 166 +---+---+---+---+---+---+---+---+ 167 8 | | - | | - | | - | | - | 168 +---+---+---+---+---+---+---+---+ 169 7 | - | | - | | - | | - | | 170 +---+---+---+---+---+---+---+---+ 171 6 | | - | | - | | - | | - | 172 +---+---+---+---+---+---+---+---+ 173 5 | - | | - | | - | | - | | 174 +---+---+---+---+---+---+---+---+ 175 4 | | - | |<K>| | - | | - | 176 +---+---+---+---+---+---+---+---+ 177 3 | - | | - | | - | | - | | 178 +---+---+---+---+---+---+---+---+ 179 2 | P | - | | - | | - | | - | 180 +---+---+---+---+---+---+---+---+ 181 1 | - | K | - | | - | | - | | 182 +---+---+---+---+---+---+---+---+ 183 a b c d e f g h 184 185 At any time, you can print the current board position in the above format to a 186 file with 187 188 : (ppos "file") 189 190 which later can be restored with 191 192 : (load "file") 193 194 195 196 There is also a plain 'sudoku' solver: 197 198 $ pil games/sudoku.l + 199 200 : (main 201 (quote 202 (5 3 0 0 7 0 0 0 0) 203 (6 0 0 1 9 5 0 0 0) 204 (0 9 8 0 0 0 0 6 0) 205 (8 0 0 0 6 0 0 0 3) 206 (4 0 0 8 0 3 0 0 1) 207 (7 0 0 0 2 0 0 0 6) 208 (0 6 0 0 0 0 2 8 0) 209 (0 0 0 4 1 9 0 0 5) 210 (0 0 0 0 8 0 0 7 9) ) ) 211 +---+---+---+---+---+---+---+---+---+ 212 9 | 5 3 | 7 | | 213 + + + + + + + + + + 214 8 | 6 | 1 9 5 | | 215 + + + + + + + + + + 216 7 | 9 8 | | 6 | 217 +---+---+---+---+---+---+---+---+---+ 218 6 | 8 | 6 | 3 | 219 + + + + + + + + + + 220 5 | 4 | 8 3 | 1 | 221 + + + + + + + + + + 222 4 | 7 | 2 | 6 | 223 +---+---+---+---+---+---+---+---+---+ 224 3 | 6 | | 2 8 | 225 + + + + + + + + + + 226 2 | | 4 1 9 | 5 | 227 + + + + + + + + + + 228 1 | | 8 | 7 9 | 229 +---+---+---+---+---+---+---+---+---+ 230 a b c d e f g h i 231 232 Type 233 234 : (go) 235 236 to let it search for a solution.