From 395c727c14bc8543031bc4c232682cace7bfdc33 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Tue, 31 May 2016 12:52:03 +0200 Subject: [PATCH] init --- stupidIATictactoe.php | 23 +++++++++++++ tictactoe.php | 80 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 stupidIATictactoe.php create mode 100644 tictactoe.php diff --git a/stupidIATictactoe.php b/stupidIATictactoe.php new file mode 100644 index 0000000..3bbe532 --- /dev/null +++ b/stupidIATictactoe.php @@ -0,0 +1,23 @@ + $betterScore ){ + $betterCell = $cellKey; + $betterScore= $sc; + } + } + } + return array($betterCell,$betterScore); +} + +//count free cases +$freeCells=0; +for($x = 0; $x < 3; $x++){ + for($y = 0; $y < 3; $y++){ + if($message['board'][$x."-".$y] == ""){ + $freeCells ++; + }elseif($message['board'][$x."-".$y] !== $message['you']){ + $hisSymbol=$message['board'][$x."-".$y]; + } + } +} + +if(!isset($hisSymbol)){ + if($message['you'] == 'X'){ + $hisSymbol='O'; + }else{ + $hisSymbol="X"; + } +} + + +echo '{"play":"'.choose_better_cell($message['board'],$message['you'], $hisSymbol,9 - $freeCells).'"}';