.
This commit is contained in:
parent
4d4f6395ec
commit
8f60d21b04
|
@ -83,7 +83,7 @@ switch ($_POST['act']){
|
||||||
die;
|
die;
|
||||||
break;
|
break;
|
||||||
case "play":
|
case "play":
|
||||||
|
$logs = "";
|
||||||
//check for correct game ID
|
//check for correct game ID
|
||||||
if($_POST['gameId'] <> $_SESSION['gameId']){
|
if($_POST['gameId'] <> $_SESSION['gameId']){
|
||||||
echo '{"status":"error"}';
|
echo '{"status":"error"}';
|
||||||
|
@ -96,20 +96,52 @@ switch ($_POST['act']){
|
||||||
$board[$botCount] = $bots[$botCount]->getTail();
|
$board[$botCount] = $bots[$botCount]->getTail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$busyCells = array(); //les cases prises
|
||||||
$responses = array();
|
$responses = array();
|
||||||
|
$loosingBots = array();
|
||||||
|
$targets = array();
|
||||||
for ($botCount = 0; $botCount < count($bots); $botCount ++){
|
for ($botCount = 0; $botCount < count($bots); $botCount ++){
|
||||||
$messageArr = array(
|
|
||||||
'game-id' => '',
|
|
||||||
'action' => 'play-turn',
|
|
||||||
'game' => 'tron',
|
|
||||||
'board' => $board,
|
|
||||||
'player-index' => $botCount, // To do: verifier que ça restera le même à chaque tour
|
|
||||||
'players' => $_SESSION['players']
|
|
||||||
);
|
|
||||||
|
|
||||||
$responses[$botCount] = get_IA_Response($bots[$botCount]->getURL(),$messageArr);
|
if($bots[$botCount]->getStatus()){
|
||||||
|
$messageArr = array(
|
||||||
|
'game-id' => '',
|
||||||
|
'action' => 'play-turn',
|
||||||
|
'game' => 'tron',
|
||||||
|
'board' => $board,
|
||||||
|
'player-index' => $botCount, // To do: verifier que ça restera le même à chaque tour
|
||||||
|
'players' => $_SESSION['players']
|
||||||
|
);
|
||||||
|
|
||||||
|
$busyCells = array_merge($busyCells, $bots[$botCount]->getTail());
|
||||||
|
$responses[$botCount] = get_IA_Response($bots[$botCount]->getURL(),$messageArr);
|
||||||
|
if(in_array($responses[$botCount]['responseArr'], $busyCells)){
|
||||||
|
//this bot plays on a non empty cell, it looses
|
||||||
|
$bots[$botCount]->loose();
|
||||||
|
$logs.= $bots[$botCount]->getName()." Played on a non empty cell, he loses.<br/>";
|
||||||
|
$loosingBots[] = $bots[$botCount]->getName();
|
||||||
|
}else{
|
||||||
|
$targets[] = $responses[$botCount]['responseArr'];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for ($botCount = 0; $botCount < count($bots); $botCount ++){
|
||||||
|
if($bots[$botCount]->getStatus()){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//dans les bots qui restent, y en a t-il qui jouent sur ma ême case?
|
||||||
|
|
||||||
|
|
||||||
|
//save pat game betwin loosing bots
|
||||||
|
save_draw_bots($loosingBots);
|
||||||
|
//find losing bots
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print_r($responses);
|
print_r($responses);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
function save_draw_bots($arr){
|
||||||
|
/*
|
||||||
|
* Recursive function who save all combionaisons of draw matches
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(count($arr) < 2){
|
||||||
|
return;
|
||||||
|
}else{
|
||||||
|
$a = $arr[0];
|
||||||
|
array_shift($arr)
|
||||||
|
foreach($arr as $bot){
|
||||||
|
save_battle('tron',$a,$bot,0);
|
||||||
|
}
|
||||||
|
save_draw_bots($arr);
|
||||||
|
}
|
||||||
|
}
|
||||||
class TronPlayer{
|
class TronPlayer{
|
||||||
private $url;
|
private $url;
|
||||||
private $name;
|
private $name;
|
||||||
|
@ -41,7 +58,6 @@ class TronPlayer{
|
||||||
}
|
}
|
||||||
$headCoords = end($this->tail);
|
$headCoords = end($this->tail);
|
||||||
|
|
||||||
|
|
||||||
switch ($dir){
|
switch ($dir){
|
||||||
case "y+":
|
case "y+":
|
||||||
$targetCoords = array($headCoords[0],$headCoords[1]++);
|
$targetCoords = array($headCoords[0],$headCoords[1]++);
|
||||||
|
@ -57,13 +73,16 @@ class TronPlayer{
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
$this->tail[] = $targetCoords;
|
$this->tail[] = $targetCoords;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loose(){
|
||||||
|
$this->state = false;
|
||||||
|
$this->tail = array();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
public function __construct($id,$initialX,$initialY,$initialDirection){
|
public function __construct($id,$initialX,$initialY,$initialDirection){
|
||||||
$lnBdd = conn_bdd();
|
$lnBdd = conn_bdd();
|
||||||
$rs = mysqli_query($lnBdd,
|
$rs = mysqli_query($lnBdd,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user