5 Inspired by WarGames ;D
8 echo("Tic-Tac-Toe (<- Harvie 2oo7)\n");
9 echo("Inspired by WarGames ;D\n");
11 //Settings////////////////////////////////////////////////////////
19 $p = false; //false - O; true - X;
20 //Artificial inteligency:
21 $ai = 3; /* AI (very poor == rand(1,9) ;)
29 //Functions//////////////////////////////////////////////////////
31 function ttt_print($ttt) {
32 $v = $GLOBALS["versep"];
33 $h = $GLOBALS["horsep"];
36 echo($ttt[7].$v.$ttt[8].$v.$ttt[9]."\n");
38 echo($ttt[4].$v.$ttt[5].$v.$ttt[6]."\n");
40 echo($ttt[1].$v.$ttt[2].$v.$ttt[3]."\n");
45 function ttt_match($ttt, $place, $player) {
46 $x = $GLOBALS["cross"];
47 $o = $GLOBALS["circl"];
49 if( ($place>0 && $place<10) && ($ttt[$place] != $x && $ttt[$place] != $o) && is_numeric($place) ) {
50 $ttt[$place] = $player;
51 } else { $GLOBALS["err"] = true; }
56 function ttt_check($ttt) {
57 $x = $GLOBALS["cross"];
58 $o = $GLOBALS["circl"];
60 if( $ttt[7] == $ttt[8] && $ttt[8] == $ttt[9] ) { return 1; }
61 if( $ttt[4] == $ttt[5] && $ttt[5] == $ttt[6] ) { return 1; }
62 if( $ttt[1] == $ttt[2] && $ttt[2] == $ttt[3] ) { return 1; }
64 if( $ttt[7] == $ttt[4] && $ttt[4] == $ttt[1] ) { return 1; }
65 if( $ttt[8] == $ttt[5] && $ttt[5] == $ttt[2] ) { return 1; }
66 if( $ttt[9] == $ttt[6] && $ttt[6] == $ttt[3] ) { return 1; }
68 if( $ttt[7] == $ttt[5] && $ttt[5] == $ttt[3] ) { return 1; }
69 if( $ttt[1] == $ttt[5] && $ttt[5] == $ttt[9] ) { return 1; }
71 for($i=1;$i<strlen($ttt);$i++
) {
72 if($ttt[$i] != $x && $ttt[$i] != $o) { return 0; }
77 //Code///////////////////////////////////////////////////////////
79 //Init///////////////////////////////////////////////////////////
80 $__STDIN__ = fopen("php://stdin", "rb");
82 $time = @explode
(",", trim(@shell_exec
("echo %time%"))); @srand
(time()*$time[1]); //print_r($time); //Debug
84 //Go/////////////////////////////////////////////////////////////
87 if($p) { $player = $cross; } else { $player = $circl; }
91 if( ($p == $ai ||
$ai == 3) && $ai != 2 ) {
96 while( !is_numeric($c) ) { $c = fgetc($__STDIN__); }
100 $ttt = ttt_match($ttt, $c, $player); if($err) { $err = false; echo("-"); continue; }
101 elseif( ($p == $ai ||
$ai == 3) && $ai != 2 ) { echo("\n"); }
105 if(ttt_check($ttt) == -1) { echo("!!! Nobody won !!!\n"); break; }
106 if(ttt_check($ttt)) { echo("!!! Player $player won !!!\n"); break; }
This page took 0.391995 seconds and 4 git commands to generate.