1: 2: logic 3: { 4: local array lines 5: { 0, 1, 2, 6: 3, 4, 5, 7: 6, 7, 8, 8: 0, 3, 6, 9: 1, 4, 7, 10: 2, 5, 8, 11: 0, 4, 8, 12: 2, 4, 6 } 13: 14: array board 15: { 0, 0, 0, 16: 0, 0, 0, 17: 0, 0, 0 } 18: 19: int turn { 1 } 20: int win { 0 } 21: 22: for i ( 1 .. 2 ) 23: { 24: for j ( 0 .. 8 ) 25: { 26: when 27: { 28: (turn == i) 29: and (board[j] == 0) 30: } 31: allow 32: { 33: board[j] = i; 34: turn = 3 - i; 35: } 36: label { "player " i " move to (" (j/3) " , " (j%3) ")" } 37: } 38: } 39: 40: for j ( 0 .. 7 ) 41: { 42: when 43: { 44: (board[lines[j*3]] != 0) 45: and ( (board[lines[j*3]] == board[lines[(j*3)+1]]) 46: and (board[lines[(j*3)+1]] == board[lines[(j*3)+2]])) 47: } 48: allow 49: { 50: win = board[lines[j*3]]; 51: } 52: label { "player " board[lines[j*3]] " win" } 53: } 54: } 55: 56: display 57: { 58: stringtable counters 59: { 60: " ", 61: "O", 62: "X" 63: } 64: 65: stringtable playernames 66: { 67: "error", 68: "noughts", 69: "crosses" 70: } 71: 72: box 73: { 74: content { "Noughts and crosses" } 75: } 76: 77: newline 78: 79: for j ( 0 .. 8 ) 80: { 81: box 82: { 83: width { 2em } 84: height { 2em } 85: border { 1px solid black } 86: content { counters[ board[j] ] } 87: 88: bind_action { "player 1 move to (" (j/3) " , " (j%3) ")" } 89: bind_action { "player 2 move to (" (j/3) " , " (j%3) ")" } 90: } 91: 92: if( (j % 3) == 2 ) 93: { 94: newline 95: } 96: } 97: 98: newline 99: 100: box 101: { 102: bind_action { "player 1 win" } 103: bind_action { "player 2 win" } 104: content { counters[turn] " to move"} 105: while_active { content { } } 106: } 107: 108: for j ( 1 .. 2 ) 109: { 110: box 111: { 112: content { } 113: bind_action { "player " j " win" } 114: while_active { content { "- " counters[ j ] " has won!" } } 115: } 116: } 117: }