From 8f60d21b0467ebed9f34f790f53a8dfc04f9c05d Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 4 Jul 2016 21:54:14 +0200 Subject: [PATCH] . --- src/arenas/tron/act.php | 56 +++++++++++++++++++++++++++-------- src/arenas/tron/functions.php | 25 ++++++++++++++-- 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/src/arenas/tron/act.php b/src/arenas/tron/act.php index e859faa..504158a 100644 --- a/src/arenas/tron/act.php +++ b/src/arenas/tron/act.php @@ -83,7 +83,7 @@ switch ($_POST['act']){ die; break; case "play": - + $logs = ""; //check for correct game ID if($_POST['gameId'] <> $_SESSION['gameId']){ echo '{"status":"error"}'; @@ -96,20 +96,52 @@ switch ($_POST['act']){ $board[$botCount] = $bots[$botCount]->getTail(); } + $busyCells = array(); //les cases prises $responses = array(); + $loosingBots = array(); + $targets = array(); 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.
"; + $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); diff --git a/src/arenas/tron/functions.php b/src/arenas/tron/functions.php index f8e9bf4..08039ec 100644 --- a/src/arenas/tron/functions.php +++ b/src/arenas/tron/functions.php @@ -1,5 +1,22 @@ tail); - switch ($dir){ case "y+": $targetCoords = array($headCoords[0],$headCoords[1]++); @@ -57,13 +73,16 @@ class TronPlayer{ break; default: return false; - } $this->tail[] = $targetCoords; } - + public function loose(){ + $this->state = false; + $this->tail = array(); + return false; + } public function __construct($id,$initialX,$initialY,$initialDirection){ $lnBdd = conn_bdd(); $rs = mysqli_query($lnBdd,