fixes
This commit is contained in:
parent
f873d6233d
commit
0fb60e7cf4
|
@ -1 +1 @@
|
|||
1622
|
||||
1660
|
|
@ -73,7 +73,10 @@ class Direction
|
|||
$dir->setValue(Direction::$bottom);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidDirectionException("expected 'x+', 'x-', 'y+' or 'y-'". (string)$str."received.");
|
||||
//error_log("expected 'x+', 'x-', 'y+' or 'y-'". (string)$str."received.");
|
||||
return false;
|
||||
//throw new InvalidDirectionException("expected 'x+', 'x-', 'y+' or 'y-'". (string)$str."received.");
|
||||
break;
|
||||
}
|
||||
return $dir;
|
||||
}
|
||||
|
|
|
@ -25,9 +25,10 @@ class Trail {
|
|||
}
|
||||
|
||||
if($this->contains($value)) {
|
||||
throw new AlreadyBeenAddedException(
|
||||
'value has already been added to the trail'
|
||||
);
|
||||
//throw new AlreadyBeenAddedException(
|
||||
// 'value has already been added to the trail'.$value.'|'.$this->__toString()
|
||||
//);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@ class TronGame
|
|||
$urls = array();
|
||||
$paramToSend = array();
|
||||
$board = $this->get_trails();
|
||||
//$board = $this->get_lasts_trails();
|
||||
$loosers = array();
|
||||
$lastsCells = array();
|
||||
|
||||
|
@ -108,27 +109,40 @@ class TronGame
|
|||
'player-index' => $botCount, // To do: verifier que ça restera le même à chaque tour
|
||||
'players' => $nbeBots
|
||||
);
|
||||
//!!!!!!!!!!!!! To debug
|
||||
//error_log(json_encode($paramsToSend[$botCount]));
|
||||
}
|
||||
}
|
||||
|
||||
$responses = $this->get_multi_IAS_Responses($urls,$paramsToSend);
|
||||
//print_r($responses);
|
||||
//grow bots'tails
|
||||
|
||||
//grow bots'tails
|
||||
for ($botCount = 0; $botCount < $nbeBots; $botCount++){
|
||||
if ($this->bots[$botCount]->isAlive){
|
||||
|
||||
$dir = Direction::make($responses[$botCount]['responseArr']['play']);
|
||||
if(!$dir = Direction::make($responses[$botCount]['responseArr']['play'])){
|
||||
//he loses , non conform response
|
||||
$loosers[] = $botCount;
|
||||
$this->bots[$botCount]->loose();
|
||||
}else{
|
||||
|
||||
$lastsCells[$botCount] = $this->bots[$botCount]->grow($dir);
|
||||
$lastsCells[$botCount] = $this->bots[$botCount]->grow($dir);
|
||||
if($lastsCells[$botCount] === false){
|
||||
$loosers[] = $botCount;
|
||||
$this->bots[$botCount]->loose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//test if loose
|
||||
for ($botCount = 0; $botCount < $nbeBots; $botCount++){
|
||||
for ($botCount = 0; $botCount < $nbeBots; $botCount++){
|
||||
if ($this->bots[$botCount]->isAlive){
|
||||
for( $botCount2 = 0; $botCount2 < $nbeBots; $botCount2++){
|
||||
|
||||
|
||||
//tester si collusion avec les cases actuelles
|
||||
for( $botCount2 = 0; $botCount2 < $nbeBots; $botCount2++){
|
||||
if(($botCount <> $botCount2)
|
||||
&& ($this->bots[$botCount2]->trail->contains($lastsCells[$botCount]))
|
||||
){
|
||||
|
@ -137,13 +151,13 @@ class TronGame
|
|||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->get_lasts_trails();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -218,11 +232,11 @@ class TronGame
|
|||
$nbeBots = count($this->bots);
|
||||
for ($botCount = 0; $botCount < $nbeBots; $botCount++){
|
||||
$messageArr = array(
|
||||
'game-id' => "".$this->gameId,
|
||||
'action' => 'init',
|
||||
'game-id' => "".$this->gameId,
|
||||
'action' => 'init',
|
||||
'game' => 'tron',
|
||||
'board' => '',
|
||||
'players' => $nbeBots,
|
||||
'players' => $nbeBots,
|
||||
'player-index' => $botCount
|
||||
);
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#
|
||||
# -- END LICENSE BLOCK -----------------------------------------
|
||||
|
||||
//error_log(json_encode($_SESSION,true)."\n\n");
|
||||
|
||||
require_once ("TronGame.php");
|
||||
require_once ("TronPlayer.php");
|
||||
require_once ("Direction.php");
|
||||
|
|
|
@ -12,24 +12,7 @@ function addLog(message){
|
|||
divLogs.scrollTop = divLogs.scrollHeight;
|
||||
|
||||
}
|
||||
/*
|
||||
function growTails(newPointsByPlayer){
|
||||
|
||||
var botsColor = ['cyan','darkmagenta','darkred','darkslategrey','deeppink','dodgerblue','goldenrod','grey','indigo','lightgreen','mediumslateblue','midnightblue'];
|
||||
//document.getElementById('map');
|
||||
for (var botId in newPointsByPlayer){
|
||||
|
||||
var tail = newPointsByPlayer[botId]['tail'];
|
||||
for(var coordsIx in tail){
|
||||
|
||||
coords = tail[coordsIx];
|
||||
//draw the point
|
||||
var rect=createElemNS('rect',{'x':coords[0],'y':coords[1],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'});
|
||||
document.getElementById('map').appendChild(rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
function createElemNS(type,attributes){
|
||||
//same as createElem but with ns for svg file
|
||||
var elem=document.createElementNS("http://www.w3.org/2000/svg",type);
|
||||
|
@ -92,7 +75,7 @@ function applyInitMessage(req,xd_check){
|
|||
}
|
||||
|
||||
}else{
|
||||
alert ('error ' + req.status);
|
||||
alert ('error ' + req.status + req.responseText );
|
||||
document.getElementById('fightButton').disabled=false;
|
||||
return;
|
||||
}
|
||||
|
@ -108,15 +91,6 @@ function drawMap(map){
|
|||
//draw the point
|
||||
var rect=createElemNS('rect',{'x':map[botId]['x'],'y':map[botId]['y'],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'});
|
||||
document.getElementById('map').appendChild(rect);
|
||||
/*
|
||||
for(var coordsI in map[botId]){
|
||||
coords = map[botId][coordsI];
|
||||
//draw the point
|
||||
var rect=createElemNS('rect',{'x':coords[0],'y':coords[1],'width':'2','height':'2','style':'fill:' + botsColor[botId] + ';'});
|
||||
|
||||
document.getElementById('map').appendChild(rect);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,13 +101,17 @@ function play(gameId,xd_check){
|
|||
if(req.readyState == 4){
|
||||
if(req.status == 200) {
|
||||
addLog(req.responseText);
|
||||
var reponse = JSON.parse(req.responseText);
|
||||
|
||||
|
||||
|
||||
var reponse = JSON.parse(req.responseText);
|
||||
drawMap(reponse['lap']);
|
||||
if(reponse['continue'] == '1'){
|
||||
play(gameId,xd_check);
|
||||
|
||||
setTimeout(function(){
|
||||
play(gameId,xd_check);
|
||||
} ,500);
|
||||
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
alert ('game ended');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user