# # Tic-Tac-Toe X_|_O_|_X # ver 1.0 _|_X_|_O # Dec. 10, 1998 X | | O # (5th anniversary of DOOM) # # Freeware Digita script for Kodak DC220 camera, etc. # Copyright 1998 David Park, dpark@sazan.net # http://www.sazan.net/software/ # # This script may be freely distributed, but please do not remove the # above contact information. # # Installation: # Copy this file to the System folder on your memory card # # Playing the game: # The game is located in the Games folder in the Review mode menu. Set # the mode dial to Review, press the Menu button, find the script in the # Games menu, and press the softkey to run it. # Exit at any time by pressing the Stop or Exit softkey. # # Future plans: save settings, win/loss record # name "Tic Tac Toe" mode 1 menu "Games" label "Tic Tac Toe" # Declare Variables # ----------------- # game settings declare s: sBlank, sPlayChar, sCompChar declare i: iPlayerFirst, iHard declare u: uDelay # input and return values declare u: uChoice, uOption, uSubOption # game state declare i: iPlayerTurn, iGameOver declare s: sMsg # current move declare i: iFoundMove declare u: uMove declare s: sMoveChar # grid display declare s: sA, sB, sC, sD, sE, sF, sG, sH, sI # init vars sBlank = " " sPlayChar = "X" sCompChar = "O" iPlayerFirst = 1 iHard = 0 uDelay = 4000 Begin: uChoice = 0 SetOption (1, "Play Game", 0) SetOption (2, "Help", 0) SetOption (3, "Options", 0) SetOption (4, "Exit", 0) GetOption (uChoice) if uChoice == 1 # BEGIN MAIN PROGRAM Start: # Initialize grid sA = sBlank sB = sBlank sC = sBlank sD = sBlank sE = sBlank sF = sBlank sG = sBlank sH = sBlank sI = sBlank iPlayerTurn = iPlayerFirst iGameOver = 0 DrawGrid: DisplayClear () DisplayLine (" A B C ") DisplayLine ("1 ", sA, "_|_", sB, "_|_", sC, " ") DisplayLine ("2 ", sD, "_|_", sE, "_|_", sF, " ") DisplayLine ("3 ", sG, " | ", sH, " | ", sI, " ") # check for a winner if sA != sBlank if sA == sB if sB == sC # top horizontal row iGameOver = 1 sMoveChar = sA end end if sA == sD if sD == sG # left vertical column iGameOver = 1 sMoveChar = sA end end if sA == sE if sE == sI # top-left to bottom-right diagonal iGameOver = 1 sMoveChar = sA end end end if sE != sBlank if sD == sE if sE == sF # middle horizontal row iGameOver = 1 sMoveChar = sD end end if sB == sE if sE == sH # center vertical column iGameOver = 1 sMoveChar = sB end end if sC == sE if sE == sG # top-right to bottom-left diagonal iGameOver = 1 sMoveChar = sC end end end if sI != sBlank if sG == sH if sH == sI # bottom horizontal row iGameOver = 1 sMoveChar = sG end end if sC == sF if sF == sI # right vertical column iGameOver = 1 sMoveChar = sC end end end # see if entire grid full if iGameOver == 0 sMoveChar = sBlank if sA == sBlank sMoveChar = "!" end if sB == sBlank sMoveChar = "!" end if sC == sBlank sMoveChar = "!" end if sD == sBlank sMoveChar = "!" end if sE == sBlank sMoveChar = "!" end if sF == sBlank sMoveChar = "!" end if sG == sBlank sMoveChar = "!" end if sH == sBlank sMoveChar = "!" end if sI == sBlank sMoveChar = "!" end if sMoveChar == sBlank iGameOver = 1 end end if iGameOver == 1 # determine if winner is player or computer if sMoveChar == sPlayChar sMsg = " YOU WIN!" end if sMoveChar == sCompChar sMsg = " YOU LOSE" end if sMoveChar == sBlank sMsg = " IT'S A DRAW" end DisplayLine (sMsg) Wait (uDelay) Wait (uDelay) Alert ("Would you like to play again?") goto Start end # make a move (player or computer) if iPlayerTurn == 1 DisplayLine ("Your turn...") Wait (uDelay) uMove = 0 if sA == sBlank SetOption (1, "A1", 0) end if sB == sBlank SetOption (2, "B1", 0) end if sC == sBlank SetOption (3, "C1", 0) end if sD == sBlank SetOption (4, "A2", 0) end if sE == sBlank SetOption (5, "B2", 0) end if sF == sBlank SetOption (6, "C2", 0) end if sG == sBlank SetOption (7, "A3", 0) end if sH == sBlank SetOption (8, "B3", 0) end if sI == sBlank SetOption (9, "C3", 0) end SetOption (10, "show board again", 0) GetOption (uMove) if uMove == 10 goto DrawGrid end sMoveChar = sPlayChar iPlayerTurn = -1 end if iPlayerTurn == 0 DisplayLine ("Computer's turn...") Wait (uDelay) iFoundMove = 0 if iHard == 1 # ooh, a challenge # if the computer can win with this move, it does so # this means checking all 24 possible win situations # (I could also stick in a temp char and use the win check routine: # loop on uMove, if sA(-I) == sBlank replace with sCompChar, run test, # if iGameOver then jump out of AI block, otherwise set back to sBlank, # increment uMove, and repeat. However, loops are bad ;-) if sE == sCompChar # test for two sCompChars and a space in line through center if sA == sCompChar if sI == sBlank # top-left to bottom-right diagonal uMove = 9 iFoundMove = 1 end end if sB == sCompChar if sH == sBlank # center vertical column uMove = 8 iFoundMove = 1 end end if sC == sCompChar if sG == sBlank # top-right to bottom-left diagonal uMove = 7 iFoundMove = 1 end end if sD == sCompChar if sF == sBlank # middle horizontal row uMove = 6 iFoundMove = 1 end end if sF == sCompChar if sD == sBlank # middle horizontal row uMove = 4 iFoundMove = 1 end end if sG == sCompChar if sC == sBlank # top-right to bottom-left diagonal uMove = 3 iFoundMove = 1 end end if sH == sCompChar if sB == sBlank # center vertical column uMove = 2 iFoundMove = 1 end end if sI == sCompChar if sA == sBlank # top-left to bottom-right diagonal uMove = 1 iFoundMove = 1 end end end if sA == sCompChar # test lines through top-left corner if sB == sCompChar if sC == sBlank # top horizontal row uMove = 3 iFoundMove = 1 end end if sC == sCompChar if sB == sBlank # top horizontal row uMove = 2 iFoundMove = 1 end end if sD == sCompChar if sG == sBlank # left vertical column uMove = 7 iFoundMove = 1 end end if sG == sCompChar if sD == sBlank # left vertical column uMove = 4 iFoundMove = 1 end end end if sC == sCompChar # test lines through top-right corner if sB == sCompChar if sA == sBlank # top horizontal row uMove = 1 iFoundMove = 1 end end if sF == sCompChar if sI == sBlank # right vertical column uMove = 9 iFoundMove = 1 end end end if sG == sCompChar # test lines through bottom-left corner if sD == sCompChar if sA == sBlank # left vertical column uMove = 1 iFoundMove = 1 end end if sH == sCompChar if sI == sBlank # bottom horizontal row uMove = 9 iFoundMove = 1 end end end if sI == sCompChar # test lines through bottom-right corner if sC == sCompChar if sF == sBlank # right vertical column uMove = 6 iFoundMove = 1 end end if sF == sCompChar if sC == sBlank # right vertical column uMove = 3 iFoundMove = 1 end end if sG == sCompChar if sH == sBlank # bottom horizontal row uMove = 8 iFoundMove = 1 end end if sH == sCompChar if sG == sBlank # bottom horizontal row uMove = 7 iFoundMove = 1 end end end if sE == sBlank # test opposite corners if sA == sCompChar if sI == sCompChar # top-left to bottom-right diagonal uMove = 5 iFoundMove = 1 end end if sB == sCompChar if sH == sCompChar # center vertical column uMove = 5 iFoundMove = 1 end end if sC == sCompChar if sG == sCompChar # top-right to bottom-left diagonal uMove = 5 iFoundMove = 1 end end if sD == sCompChar if sF == sCompChar # middle horizontal row uMove = 5 iFoundMove = 1 end end if iFoundMove == 0 # the computer can't win this turn # so it picks the middle over any other space uMove = 5 iFoundMove = 1 end end end if iFoundMove == 0 # brain-dead computer AI # btw, the fall-through IFs below are intentional if sI == sBlank uMove = 9 end if sH == sBlank uMove = 8 end if sG == sBlank uMove = 7 end if sF == sBlank uMove = 6 end if sE == sBlank uMove = 5 end if sD == sBlank uMove = 4 end if sC == sBlank uMove = 3 end if sB == sBlank uMove = 2 end if sA == sBlank uMove = 1 end end sMoveChar = sCompChar end iPlayerTurn = iPlayerTurn + 1 # update grid with new move if uMove == 1 sA = sMoveChar end if uMove == 2 sB = sMoveChar end if uMove == 3 sC = sMoveChar end if uMove == 4 sD = sMoveChar end if uMove == 5 sE = sMoveChar end if uMove == 6 sF = sMoveChar end if uMove == 7 sG = sMoveChar end if uMove == 8 sH = sMoveChar end if uMove == 9 sI = sMoveChar end goto DrawGrid # END MAIN PROGRAM end if uChoice == 2 # help message Alert ("You already know the rules. Settings can be viewed/changed in the Options menu.") Alert ("When you start, the tic-tac-toe board will be displayed for a few seconds.") Alert ("Then you choose where you want to move, such as A1, B3, etc., from a list.") end if uChoice == 3 # change settings Settings: uOption = 0 SetOption (1, "Difficulty", 0) SetOption (2, "Player symbol", 0) SetOption (3, "Turn order", 0) SetOption (10, "back", 0) GetOption (uOption) if uOption == 1 uSubOption = 0 SetOption (1, "Easy", iHard == 0) SetOption (2, "Hard", iHard == 1) SetOption (10, "back", 0) GetOption (uSubOption) if uSubOption == 1 iHard = 0 end if uSubOption == 2 iHard = 1 end goto Settings end if uOption == 2 uSubOption = 0 SetOption (1, "Player X, Camera O", sPlayChar=="X") SetOption (2, "Player O, Camera X", sPlayChar=="O") SetOption (10, "back", 0) GetOption (uSubOption) if uSubOption == 1 sPlayChar = "X" sCompChar = "O" end if uSubOption == 2 sPlayChar = "O" sCompChar = "X" end goto Settings end if uOption == 3 uSubOption = 0 SetOption (1, "Player moves first", iPlayerFirst == 1) SetOption (2, "Camera moves first", iPlayerFirst == 0) SetOption (10, "back", 0) GetOption (uSubOption) if uSubOption == 1 iPlayerFirst = 1 end if uSubOption == 2 iPlayerFirst = 0 end goto Settings end end if uChoice == 4 exitscript end goto Begin