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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 31: 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 32: } 33: 34: int numRobots {8} 35: array robotX { 2, 4, 19, 15, 13, 8, 9, 17 } 36: array robotY { 8, 4, 4, 5, 7, 2, 16, 15 } 37: 38: array xMoves { -1, 0, 1, -1, 1, -1, 0, 1 } 39: array yMoves { 1, 1, 1, 0, 0, -1, -1, -1 } 40: 41: // Generate a random board 42: when 43: { 44: (1 == 1) 45: } 46: allow 47: { 48: for y (0 .. (boardHeight - 1)) 49: { 50: for x (0 .. (boardWidth - 1)) 51: { 52: board[x + (y * boardWidth)] = TILE_EMPTY; 53: } 54: } 55: for i (0..(numRobots-1)) 56: { 57: robotX[i] = random[boardWidth]; 58: robotY[i] = random[boardHeight]; 59: board[robotX[i] + (robotY[i] * boardWidth)] = board[robotX[i] + (robotY[i] * boardWidth)] + TILE_ROBOT; 60: } 61: playerX = random[boardWidth]; 62: playerY = random[boardHeight]; 63: } 64: label 65: { 66: "Reset" 67: } 68: 69: for p (0..7) 70: { 71: // Move player. 72: when 73: { 74: ((playerX + xMoves[p]) >= 0) 75: and ((playerX + xMoves[p]) < boardWidth) 76: and ((playerY + yMoves[p]) >= 0) 77: and ((playerY + yMoves[p]) < boardHeight) 78: } 79: allow 80: { 81: playerX = (playerX + xMoves[p]); 82: playerY = (playerY + yMoves[p]); 83: } 84: label 85: { 86: "Player dx=" xMoves[p] " dy=" yMoves[p] "." 87: } 88: } 89: 90: for r (0 .. (numRobots - 1)) 91: { 92: // Move each robot toward the player, killing him if he's hit. 93: when 94: { 95: (playerX > robotX[r]) 96: and (playerY > robotY[r]) 97: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 98: } 99: allow 100: { 101: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 102: board[robotX[r] + 1 + ((robotY[r] + 1) * boardWidth)] = board[robotX[r] + 1 + ((robotY[r] + 1) * boardWidth)] + TILE_ROBOT; 103: robotX[r] = robotX[r] + 1; 104: robotY[r] = robotY[r] + 1; 105: } 106: label 107: { 108: "Robot move" 109: } 110: when 111: { 112: (playerX > robotX[r]) 113: and (playerY == robotY[r]) 114: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 115: } 116: allow 117: { 118: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 119: board[robotX[r] + 1 + (robotY[r] * boardWidth)] = board[robotX[r] + 1 + (robotY[r] * boardWidth)] + TILE_ROBOT; 120: robotX[r] = robotX[r] + 1; 121: } 122: label 123: { 124: "Robot move" 125: } 126: when 127: { 128: (playerX > robotX[r]) 129: and (playerY < robotY[r]) 130: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 131: } 132: allow 133: { 134: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 135: board[robotX[r] + 1 + ((robotY[r] - 1) * boardWidth)] = board[robotX[r] + 1 + ((robotY[r] - 1) * boardWidth)] + TILE_ROBOT; 136: robotX[r] = robotX[r] + 1; 137: robotY[r] = robotY[r] - 1; 138: } 139: label 140: { 141: "Robot move" 142: } 143: when 144: 145: { 146: (playerX == robotX[r]) 147: and (playerY > robotY[r]) 148: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 149: } 150: allow 151: { 152: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 153: board[robotX[r] + ((robotY[r] + 1) * boardWidth)] = board[robotX[r] + ((robotY[r] + 1) * boardWidth)] + TILE_ROBOT; 154: robotY[r] = robotY[r] + 1; 155: } 156: label 157: { 158: "Robot move" 159: } 160: when 161: { 162: (playerX == robotX[r]) 163: and (playerY < robotY[r]) 164: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 165: 166: } 167: allow 168: { 169: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 170: board[robotX[r] + ((robotY[r] - 1) * boardWidth)] = board[robotX[r] + ((robotY[r] - 1) * boardWidth)] + TILE_ROBOT; 171: robotY[r] = robotY[r] - 1; 172: } 173: label 174: { 175: "Robot move" 176: } 177: when 178: { 179: (playerX < robotX[r]) 180: and (playerY > robotY[r]) 181: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 182: } 183: allow 184: { 185: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 186: board[robotX[r] - 1 + ((robotY[r] + 1) * boardWidth)] = board[robotX[r] - 1 + ((robotY[r] + 1) * boardWidth)] + TILE_ROBOT; 187: robotX[r] = robotX[r] - 1; 188: robotY[r] = robotY[r] + 1; 189: } 190: label 191: { 192: "Robot move" 193: } 194: when 195: { 196: (playerX < robotX[r]) 197: and (playerY == robotY[r]) 198: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 199: } 200: allow 201: { 202: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 203: board[robotX[r] - 1 + (robotY[r] * boardWidth)] = board[robotX[r] - 1 + (robotY[r] * boardWidth)] + TILE_ROBOT; 204: robotX[r] = robotX[r] - 1; 205: } 206: label 207: { 208: "Robot move" 209: } 210: when 211: { 212: (playerX < robotX[r]) 213: and (playerY < robotY[r]) 214: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 215: } 216: allow 217: { 218: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 219: board[robotX[r] - 1 + ((robotY[r] - 1) * boardWidth)] = board[robotX[r] - 1 + ((robotY[r] - 1) * boardWidth)] + TILE_ROBOT; 220: robotX[r] = robotX[r] - 1; 221: robotY[r] = robotY[r] - 1; 222: } 223: label 224: { 225: "Robot move" 226: } 227: } 228: } 229: 230: display 231: { 232: stringtable items 233: { 234: " ", "^", "$", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*" 235: } 236: 237: box 238: { 239: content { "Robots!" } 240: } 241: newline 242: for y (0 .. (boardHeight - 1)) 243: { 244: for x (0 .. (boardWidth - 1)) 245: { 246: box 247: { 248: width { 2em } 249: height { 2em } 250: border { 1px solid black } 251: 252: content { items[board[x + (y * boardWidth)]] } 253: 254: if ((x == playerX) and (y == playerY)) 255: { 256: content { "&" } 257: if (board[x + (y * boardWidth)] != TILE_EMPTY) 258: { 259: background { #900 } 260: content { "X" } 261: } 262: } 263: } 264: } 265: newline 266: } 267: newline 268: 269: box 270: { 271: width { 2em } 272: height { 2em } 273: border { 1px solid black } 274: content { "7" } 275: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 276: { 277: bind_action { "Player dx=-1 dy=-1." } 278: bind_action { "Robot move" } 279: } 280: } 281: box 282: { 283: width { 2em } 284: height { 2em } 285: border { 1px solid black } 286: content { "8" } 287: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 288: { 289: bind_action { "Player dx=0 dy=-1." } 290: bind_action { "Robot move" } 291: } 292: } 293: box 294: { 295: width { 2em } 296: height { 2em } 297: border { 1px solid black } 298: content { "9" } 299: 300: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 301: 302: 303: { 304: bind_action { "Player dx=1 dy=-1." } 305: bind_action { "Robot move" } 306: } 307: } 308: newline 309: box 310: { 311: width { 2em } 312: height { 2em } 313: border { 1px solid black } 314: content { "4" } 315: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 316: { 317: bind_action { "Player dx=-1 dy=0." } 318: bind_action { "Robot move" } 319: } 320: } 321: box 322: { 323: width { 2em } 324: height { 2em } 325: border { 1px solid black } 326: content { "5" } 327: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 328: { 329: bind_action { "Robot move" } 330: } 331: } 332: box 333: { 334: width { 2em } 335: height { 2em } 336: border { 1px solid black } 337: content { "6" } 338: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 339: { 340: bind_action { "Player dx=1 dy=0." } 341: bind_action { "Robot move" } 342: } 343: } 344: newline 345: box 346: { 347: width { 2em } 348: height { 2em } 349: border { 1px solid black } 350: content { "1" } 351: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 352: { 353: bind_action { "Player dx=-1 dy=1." } 354: bind_action { "Robot move" } 355: } 356: } 357: box 358: { 359: width { 2em } 360: height { 2em } 361: border { 1px solid black } 362: content { "2" } 363: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 364: { 365: bind_action { "Player dx=0 dy=1." } 366: bind_action { "Robot move" } 367: } 368: } 369: box 370: { 371: width { 2em } 372: height { 2em } 373: border { 1px solid black } 374: content { "3" } 375: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 376: { 377: bind_action { "Player dx=1 dy=1." } 378: bind_action { "Robot move" } 379: } 380: } 381: newline 382: 383: box 384: { 385: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 386: { 387: content { "Make your escape!" } 388: } 389: 390: if (board[playerX + (playerY * boardWidth)] != TILE_EMPTY) 391: { 392: content { "Game over!" } 393: } 394: } 395: newline 396: box 397: { 398: border { 1px solid black } 399: content { "Regenerate" } 400: bind_action { "Reset" } 401: } 402: }