~comment It seemed terribly unfair that you can play games on a cell phone but not in survent... so I felt compelled to fix that. Send questions or comments to chris@mythtech.net Copyright 04/19/2000... This is released as freeware v1.5 *NOTE: do not run in network mode, ONLY run standalone. There is a check in Networked Survent that watches for an infinite loop, and the computer looking for a valid move can trip this check, and cause a blow error, however, it also locks itself in use, and can only be cleared by doing a clearstudy at the server, and clearing IPCs. It works fine in standalone mode. >purgesame ~prepare compile -specs [tictac, "Tic-Tac-Toe by Chris Bartlett",-quo] {Moves: 10.1 !exp,,,0} ''init moves counter >repeat $c=a,a,a,b,b,b,c,c,c; & $r=1,2,3,1,2,3,1,2,3; & $g=1,2,3,4,5,6,7,8,9 {$c$r: [2$g.1] HIDE ''init grid spot Column $c, Row $r, Grid $g !fld X O} >endrep {Auto: [50.1] ''turn on computer player Which player should be the computer? !fld X O = N Neither} {Turn: [100.1] HIDE ''init turn marker !fld ^} {Test1: [105.1] ''test first or X turn !if [100.1$]=" " or [100.1$]="O" 1 !spc,9} {Test2: [Test1] ''test O turn !if [100.1$]="X" 2 !spc,9} {GoO: [Turn] ''set O turn !if [105.1]=2 O !spc,9} {GoX: [Turn] ''set X turn !if [105.1]=1 X !spc,9} {Board: ''Display Board A B C ****************** 1 \|21| | \|24| | \|27| *To mark a square* ----------- *enter the column* 2 \|22| | \|25| | \|28| * and row in the * ----------- * format CR * 3 \|23| | \|26| | \|29| ****************** !disp,2} {testw: [200.1] !if [200.1$]<>" " ''test winner mark !goto Winner} {!if moves>=9 ''test max moves !goto tie} {preMove: !gen,b,[110.2]} ''init move {Move: [110.2] ''move !if ([turn$]="X" AND auto(<>X)) OR ([turn$]="O" AND auto(<>O)) \(12) It's \|100.1|'s turn. (moves so far: \|10.1|) Where do you want to put your \|100.1|? !fld,n,1 >repeat $c=a,a,a,b,b,b,c,c,c; & $r=1,2,3,1,2,3,1,2,3 $c$r >endrep } {autoC: [51.1] ''generate computer move !if (auto(X) AND [turn$]="X") OR (auto(O) AND [turn$]="O") !exp,,,random(2)+1} >repeat $c=a,b,c; $n=1,2,3 { [move.1] !if [autoc]=$n $c !spc,9} >endrep {!gen,b,autoc} {autor: [move+1.1] !if (auto(X) AND [turn$]="X") OR (auto(O) AND [turn$]="O") !exp,,,random(2)+1} >repeat $c=a,a,a,b,b,b,c,c,c; & $r=1,2,3,1,2,3,1,2,3 ''test occupied {!if ([move$]="$c$r" AND $c$r(X,O)) AND (([turn$]="X" AND auto(<>X)) OR ([turn$]="O" AND auto(<>O))) \(15) \fCan't go there...its taken!!!\e press to try again !disp} {!if [move$]="$c$r" AND $c$r(X,O) ''reset move if occupied !reset PreMove} {!if [move$]="$c$r" AND $c$r(<>X,O) ''do move if ok !gen,M,$c$r,[100.1]} >endrep >repeat $m=X,X,X,O,O,O; & $c=a,b,c,a,b,c; & $r=1,2,3,1,2,3 {C$c_$m: [testw] ''test column winner !if $c_1($m) AND $c_2($m) AND $c_3($m) $m !spc,9} {R$r_$m: [testw] ''test row winner !if a$r($m) AND b$r($m) AND c$r($m) $m !spc,9} >endrep >repeat $m=X,O {D1_$m: [testw] ''test diag winner !if a1($m) AND b2($m) AND c3($m) $m !spc,9} {D2_$m: [testw] !if a3($m) AND b2($m) AND c1($m) $m !spc,9} >endrep {add1: [moves] !exp,,,moves+1} ''tick a move {!goto Turn} ''loop it {Tie: ''Tie \(12) \fITS A TIE!!!\e !disp} {!spc,b} {Winner: ''Winner \(12) \f\|200.1| WINS!!!\e !disp} {!spc,b} ~end