1: 2: logic 3: { 4: int NO { 0 } 5: int YES { 1 } 6: 7: array board 8: { 0, 0, 0, 0, 0, 0, 9: 0, 0, 0, 0, 0, 0, 10: 0, 0, 0, 0, 0, 0, 11: 0, 0, 0, 0, 0, 0, 12: 0, 0, 0, 0, 0, 0, 13: 0, 0, 0, 0, 0, 0, 14: 0, 0, 0, 0, 0, 0, 15: 0, 0, 0, 0, 0, 0, 16: 0, 0, 0, 0, 0, 0, 17: 0, 0, 0, 0, 0, 0, 18: 0, 0, 0, 0, 0, 0, 19: 0, 0, 0, 0, 0, 0, 20: 0, 0, 0, 0, 0, 0, 21: 0, 0, 0, 0, 0, 0, 22: 0, 0, 0, 0, 0, 0, 23: 0, 0, 0, 0, 0, 0 24: } 25: 26: int in_progress { NO } 27: int win { NO } 28: int guess { 1 } 29: int selected { 0 } 30: int right { 0 } 31: int half_right { 0 } 32: array counted_guess { 0, 0, 0, 0 } 33: array counted_ans { 0, 0, 0, 0 } 34: 35: for i ( 1 .. 15 ) 36: { 37: for j ( 0 .. 3 ) 38: { 39: when 40: { 41: (guess == i) and (selected != 0) 42: } 43: allow 44: { 45: board[6 * i + j] = selected; 46: selected = 0; 47: } 48: label { "Put peg in " i ", " j } 49: } 50: } 51: 52: when 53: { 54: (board[6 * guess] != 0) and 55: (board[6 * guess + 1] != 0) and 56: (board[6 * guess + 2] != 0) and 57: (board[6 * guess + 3] != 0) 58: } 59: allow 60: { 61: right = 0; 62: half_right = 0; 63: 64: for i ( 0 .. 3 ) 65: { 66: counted_guess[i] = NO; 67: counted_ans[i] = NO; 68: if (board[6 * guess + i] == board[i]) 69: { 70: right = right + 1; 71: counted_guess[i] = YES; 72: counted_ans[i] = YES; 73: } 74: } 75: 76: for i ( 0 .. 3 ) 77: { 78: for j ( 0 .. 3 ) 79: { 80: if ((counted_guess[i] == NO) and (counted_ans[j] == NO) and 81: (board[6 * guess + i] == board[j])) 82: { 83: half_right = half_right + 1; 84: counted_guess[i] = YES; 85: counted_ans[j] = YES; 86: } 87: } 88: } 89: 90: board[6 * guess + 4] = right; 91: board[6 * guess + 5] = half_right; 92: guess++; 93: 94: if (right == 4) 95: { 96: win = YES; 97: } 98: } 99: label { "Submit" } 100: 101: when 102: { 103: win == YES 104: } 105: allow 106: { 107: in_progress = NO; 108: } 109: label { "You Win" } 110: 111: when 112: { 113: (guess > 15) and (win == NO) 114: } 115: allow 116: { 117: in_progress = NO; 118: } 119: label { "You Lose" } 120: 121: when 122: { 123: in_progress == NO 124: } 125: allow 126: { 127: win = NO; 128: guess = 1; 129: selected = 0; 130: in_progress = YES; 131: for i ( 1 .. 15) 132: { 133: for j ( 0 .. 5 ) 134: { 135: board[6 * i + j] = 0; 136: } 137: } 138: 139: for i ( 0 .. 3 ) 140: { 141: board[i] = random[6] + 1; 142: } 143: } 144: label { "Start" } 145: 146: when 147: { 148: (in_progress == YES) 149: } 150: allow 151: { 152: selected = 1; 153: } 154: label { "Pick black" } 155: 156: when 157: { 158: ((selected == 1) and (in_progress == YES)) 159: } 160: allow 161: { 162: selected = 0; 163: } 164: label { "Drop black" } 165: 166: when 167: { 168: (in_progress == YES) 169: } 170: allow 171: { 172: selected = 2; 173: } 174: label { "Pick red" } 175: 176: when 177: { 178: ((selected == 2) and (in_progress == YES)) 179: } 180: allow 181: { 182: selected = 0; 183: } 184: label { "Drop red" } 185: 186: when 187: { 188: (in_progress == YES) 189: } 190: allow 191: { 192: selected = 3; 193: } 194: label { "Pick blue" } 195: 196: when 197: { 198: ((selected == 3) and (in_progress == YES)) 199: } 200: allow 201: { 202: selected = 0; 203: } 204: label { "Drop blue" } 205: 206: when 207: { 208: (in_progress == YES) 209: } 210: allow 211: { 212: selected = 4; 213: } 214: label { "Pick green" } 215: 216: when 217: { 218: ((selected == 4) and (in_progress == YES)) 219: } 220: allow 221: { 222: selected = 0; 223: } 224: label { "Drop green" } 225: 226: when 227: { 228: (in_progress == YES) 229: } 230: allow 231: { 232: selected = 5; 233: } 234: label { "Pick yellow" } 235: 236: when 237: { 238: ((selected == 5) and (in_progress == YES)) 239: } 240: allow 241: { 242: selected = 0; 243: } 244: label { "Drop yellow" } 245: 246: when 247: { 248: (in_progress == YES) 249: } 250: allow 251: { 252: selected = 6; 253: } 254: label { "Pick fuchsia" } 255: 256: when 257: { 258: ((selected == 6) and (in_progress == YES)) 259: } 260: allow 261: { 262: selected = 0; 263: } 264: label { "Drop fuchsia" } 265: } 266: 267: display 268: { 269: box 270: { 271: content { "Mastermind" } 272: } 273: 274: newline 275: 276: for j ( 0 .. 3 ) 277: { 278: box 279: { 280: width { 2em } 281: height { 2em } 282: content { " " } 283: border { 1px solid black } 284: padding { 3px } 285: if (in_progress == YES) 286: { 287: content { "?" } 288: } 289: if (in_progress == NO) 290: { 291: if ( board[j] == 1 ) 292: { 293: background { black } 294: } 295: if ( board[j] == 2 ) 296: { 297: background { red } 298: } 299: if ( board[j] == 3 ) 300: { 301: background { blue } 302: } 303: if ( board[j] == 4 ) 304: { 305: background { green } 306: } 307: if ( board[j] == 5 ) 308: { 309: background { yellow } 310: } 311: if ( board[j] == 6 ) 312: { 313: background { fuchsia } 314: } 315: } 316: } 317: } 318: 319: box 320: { 321: width { 2em } 322: height { 2em } 323: content { " " } 324: border { 1px solid white } 325: } 326: box 327: { 328: width { 2em } 329: height { 2em } 330: content { " " } 331: border { 1px solid white } 332: } 333: 334: newline 335: 336: for i ( 1 .. 15 ) 337: { 338: for j ( 0 .. 3 ) 339: { 340: box 341: { 342: width { 2em } 343: height { 2em } 344: content { " " } 345: if ( (selected == 0) or (guess != i)) 346: { 347: border { 1px solid black } 348: padding { 3px } 349: } 350: if ( (selected != 0) and (guess == i)) 351: { 352: border { 4px solid aqua } 353: } 354: 355: if ( board[6 * i + j] == 1 ) 356: { 357: background { black } 358: } 359: if ( board[6 * i + j] == 2 ) 360: { 361: background { red } 362: } 363: if ( board[6 * i + j] == 3 ) 364: { 365: background { blue } 366: } 367: if ( board[6 * i + j] == 4 ) 368: { 369: background { green } 370: } 371: if ( board[6 * i + j] == 5 ) 372: { 373: background { yellow } 374: } 375: if ( board[6 * i + j] == 6 ) 376: { 377: background { fuchsia } 378: } 379: 380: bind_action { "Put peg in " i ", " j } 381: while_active { border { 4px solid aqua } padding { 0px } } 382: } 383: } 384: 385: box 386: { 387: width { 2em } 388: height { 2em } 389: border { 1px solid black } 390: background { silver } 391: content { board[6 * i + 4] } 392: } 393: box 394: { 395: width { 2em } 396: height { 2em } 397: border { 1px solid black } 398: content { board[6 * i + 5] } 399: } 400: newline 401: } 402: 403: newline 404: newline 405: box 406: { 407: width { 2em } 408: height { 2em } 409: content { " " } 410: background { black } 411: if ( selected != 1 ) 412: { 413: border { 1px solid black } 414: } 415: if ( selected == 1 ) 416: { 417: border { 4px solid black } 418: } 419: bind_action { "Pick black" } 420: bind_action { "Drop black" } 421: } 422: box 423: { 424: width { 2em } 425: height { 2em } 426: content { " " } 427: background { red } 428: if ( selected != 2 ) 429: { 430: border { 1px solid black } 431: } 432: if ( selected == 2 ) 433: { 434: border { 4px solid black } 435: } 436: bind_action { "Pick red" } 437: bind_action { "Drop red" } 438: } 439: box 440: { 441: width { 2em } 442: height { 2em } 443: content { " " } 444: background { blue } 445: if ( selected != 3 ) 446: { 447: border { 1px solid black } 448: } 449: if ( selected == 3 ) 450: { 451: border { 4px solid black } 452: } 453: bind_action { "Pick blue" } 454: bind_action { "Drop blue" } 455: } 456: box 457: { 458: width { 2em } 459: height { 2em } 460: content { " " } 461: background { green } 462: if ( selected != 4 ) 463: { 464: border { 1px solid black } 465: } 466: if ( selected == 4 ) 467: { 468: border { 4px solid black } 469: } 470: bind_action { "Pick green" } 471: bind_action { "Drop green" } 472: } 473: box 474: { 475: width { 2em } 476: height { 2em } 477: content { " " } 478: background { yellow } 479: if ( selected != 5 ) 480: { 481: border { 1px solid black } 482: 483: } 484: if ( selected == 5 ) 485: { 486: border { 4px solid black } 487: } 488: bind_action { "Pick yellow" } 489: bind_action { "Drop yellow" } 490: } 491: box 492: { 493: width { 2em } 494: height { 2em } 495: content { " " } 496: background { fuchsia } 497: if ( selected != 6 ) 498: { 499: border { 1px solid black } 500: } 501: if ( selected == 6 ) 502: { 503: border { 4px solid black } 504: } 505: bind_action { "Pick fuchsia" } 506: bind_action { "Drop fuchsia" } 507: } 508: 509: newline 510: box 511: { 512: content { } 513: border { 1px solid black } 514: bind_action { "Start" } 515: while_active { content { "Start a game" } } 516: } 517: box 518: { 519: content { } 520: border { 1px solid black } 521: bind_action { "Submit" } 522: while_active { content { "Submit your guess" } } 523: } 524: box 525: { 526: content { } 527: border { 1px solid black } 528: bind_action { "You Win" } 529: while_active { content { "You win! Click to see solution" } } 530: } 531: box 532: { 533: content { } 534: border { 1px solid black } 535: bind_action { "You Lose" } 536: while_active { content { "You lose. Click to see solution" } } 537: } 538: }