programmingChallenges/morpionsFights/Master/stupidIa.php

31 lines
712 B
PHP
Raw Normal View History

2015-11-09 18:46:55 +01:00
<?php
2015-11-10 15:41:07 +01:00
/*
* Tic Tac Toe stupid IA
* For programming challenge https://github.com/jeannedhack/programmingChallenges
* Gnieark 2015
* licensed under the Do What the Fuck You Want to Public License http://www.wtfpl.net/
*/
2015-11-09 18:46:55 +01:00
$cases=array("0-0","0-1","0-2","1-0","1-1","1-2","2-0","2-1","2-2");
2015-11-10 15:41:07 +01:00
//filling array
2015-11-09 18:46:55 +01:00
$freeCases=array();
foreach($cases as $case){
if (!isset($_GET[$case])){
echo "wrong parameters ".$case; die;
}
if($_GET[$case]==""){
$freeCases[]=$case;
}
}
if(!isset($_GET['you'])){
echo "wrong parameters 2"; die;
}
if (count($freeCases)==0){
2015-11-11 18:33:38 +01:00
echo "error. Grid is full, bitch!";
2015-11-09 18:46:55 +01:00
die;
}
2015-11-10 15:41:07 +01:00
//have all parameters lets play the game
2015-11-10 15:41:48 +01:00
//Stupid IA, just random
2015-11-09 18:46:55 +01:00
shuffle($freeCases);
echo $freeCases[0];