Tic-Tac-Toe 2.3 Copyright (C) 1997 H†kon Stordahl E-mail : stordahl@usa.net Homepage: http://stordahl.home.ml.org/ Date : 01.10.97 Model : CASIO CFX-9850G Calculator Notes -------------------------------------------------------------------------------- This program is the calculator version of the classic game you all know, which purpose is to get 3 crosses or circles in a row. The game enables you to play against the calculator, which is almost unbeatable. To start the game, press [1] while you're in the title-screen. Use the arrow keys and the [EXE] key to place your cross. If you want to quit, then press [EXIT]. Symbol: Description: Key(s): -------------------------------------------------------------------------------- -> Assginment operator Above [AC/ON] * Multiplication Below [DEL] / Division Below [AC/ON] (-) Unary minus Below [+] = Equal to [SHIFT] [.] <> Not equal to [SHIFT] [VARS] [F6] [F3] [F2] >= Greater than or equal to [SHIFT] [VARS] [F6] [F3] [F5] <= Less than or equal to [SHIFT] [VARS] [F6] [F3] [F6] => If-Then [SHIFT] [VARS] [F3] [F3] \sqrt Square root [SHIFT] [X^2] \slash / (slash) [F6] [F5] \{i} \sqrt(-1) [OPTN] [F3] [F1] Frac Returns fractional part of argument [OPTN] [F6] [F4] [F3] ClrText Clear the text screen [SHIFT] [VARS] [F6] [F1] [F1] Getkey Determine keypress [SHIFT] [VARS] [F6] [F4] [F2] Locate Display variable at the given coords [SHIFT] [VARS] [F6] [F4] [F1] { Left brace [SHIFT] [*] } Right brace [SHIFT] [/] [ Left bracket [SHIFT] [+] ] Right bracket [SHIFT] [-] List List-variable [OPTN] [F1] [F1] Sum The sum of all entries in the list [OPTN] [F1] [F6] [F6] [F1] And Logical And operator [OPTN] [F6] [F6] [F4] [F1] Or Logical Or operator [OPTN] [F6] [F6] [F4] [F2] Not Logical Not operator [OPTN] [F6] [F6] [F4] [F3] File name: TTT Variables: C, E, G, I, J, K, L, M, N, O, P, Q, R, Z, Mat T -------------------------------------------------------------------------------- ViewWindow 1,127,1,1,63,1 AxesOff GridOff LabelOff Cls RclPict 1 Text 33,2,"1. START GAME" PxlOff 1,1 Do Getkey->C LpWhile C<>72 And C<>62 C=72=>0->N C=62=>1->N Do [[0,0,0][0,0,0][0,0,0]]->Mat T Cls 2->O 'Draw grid For O->G To 62 Step 20 F-Line G,2,G,62 F-Line O,G,62,G Next Text 2,64,"TIC-TAC-TOE 2.3" 2->I 2->J O+20(I-1)->K 2+20(J-1)->L PxlChg L+5,K+10 PxlChg L+10,K+5 PxlChg L+15,K+10 PxlChg L+10,K+15 PxlOff 1,1 Do 'Player turn 1->P Do Getkey->C If C=31 And Mat T[I,J]=0 Then 0->P 1->Mat T[I,J] 2+O+20(I-1)->K 2+2+20(3-J)->L F-Line K,L,K+16,L+16 F-Line K,L+16,K+16,L IfEnd If C=28 Or C=37 Or C=38 Or C=27 Then O+20(I-1)->K 2+20(J-1)->L PxlChg L+5,K+10 PxlChg L+10,K+5 PxlChg L+15,K+10 PxlChg L+10,K+15 C=28 And J>1=>J-1->J C=37 And J<3=>J+1->J C=38 And I>1=>I-1->I C=27 And I<3=>I+1->I O+20(I-1)->K 2+20(J-1)->L PxlChg L+5,K+10 PxlChg L+10,K+5 PxlChg L+15,K+10 PxlChg L+10,K+15 PxlOff 1,1 IfEnd LpWhile P And C<>47 1->W Prog "WIN" 'CPU/Opponent turn If C<>47 And (Not W) Then 3->Z 0->E While (Z>1) And (Not E) Z-1->Z For 1->R To 3 0->Q For 1->M To 3 (Mat T[M,R]=Z)=>Q+1->Q (Mat T[M,R]=0)=>M->N Next If (Q=2) And (Mat T[N,R]=0) Then 1->E N->K R->L Break IfEnd Next If Not E Then For 1->R To 3 0->Q For 1->M To 3 (Mat T[R,M]=Z)=>Q+1->Q (Mat T[R,M]=0)=>M->N Next If (Q=2) And (Mat T[R,N]=0) Then 1->E N->L R->K Break IfEnd Next IfEnd If Not E Then 0->Q For 1->M To 3 (Mat T[M,M]=Z)=>Q+1->Q (Mat T[M,M]=0)=>M->N Next If (Q=2) And (Mat T[N,N]=0) Then 1->E N->K N->L IfEnd IfEnd If Not E Then 0->Q For 1->M To 3 (Mat T[4-M,M]=Z)=>Q+1->Q (Mat T[4-M,M]=0)=>M->N Next If (Q=2) And (Mat T[4-N,N]=0) Then 1->E 4-N->K N->L IfEnd IfEnd WhileEnd If (Not E) And (Mat T[2,2]=1) Then For 1->M To 3 Step 2 For 1->N To 3 Step 2 If Mat T[M,N]=0 Then 1->E M->K N->L IfEnd Next Next IfEnd If (Not E) And (Mat T[2,2]=0) Then 1->E 2->K 2->L IfEnd If Not E Then Do Int (3Ran#)+1->K Int (3Ran#)+1->L LpWhile Mat T[K,L]<>0 IfEnd 2->Mat T[K,L] 8+2+O+20(K-1)->K 8+2+2+20(3-L)->L Circle K,L,8 2->W Prog "WIN" IfEnd LpWhile C<>47 And (Not W) W=1=>Text 51,64,"YOU WIN" W=2=>Text 51,64,"YOU LOOSE" W=3=>Text 51,64,"DRAW" Text 57,64,"PLAY AGAIN?(Y\slashN)" PxlOff 1,1 Do Getkey->C LpWhile C<>32 And C<>64 LpWhile C=32 AxesOn ViewWindow (-)6.3,6.3,1,(-)3.1,3.1,1 Cls ClrText -------------------------------------------------------------------------------- File name: WIN Input : W, Mat T Output : W Variables: A, B, D, W -------------------------------------------------------------------------------- Not ((Mat T[1,1]=W And Mat T[2,1]=W And Mat T[3,1]=W) Or (Mat T[1,2]=W And Mat T[2,2]=W And Mat T[3,2]=W) Or (Mat T[1,3]=W And Mat T[2,3]=W And Mat T[3,3]=W))->A Not ((Mat T[1,1]=W And Mat T[1,2]=W And Mat T[1,3]=W) Or (Mat T[2,1]=W And Mat T[2,2]=W And Mat T[2,3]=W) Or (Mat T[3,1]=W And Mat T[3,2]=W And Mat T[3,3]=W))->B Not ((Mat T[1,1]=W And Mat T[2,2]=W And Mat T[3,3]=W) Or (Mat T[1,3]=W And Mat T[2,2]=W And Mat T[3,1]=W))->D A And B And D=>0->W If Not W Then 3->W For 1->A To 3 For 1->B To 3 Mat T[A,B]=0=>0->W Next Next IfEnd --------------------------------------------------------------------------------