it works, lets debug

pull/96/head
root 8 years ago
parent 9a2224f019
commit 1f1f6dcd47

@ -1 +1 @@
1671
1677

@ -1,16 +1,26 @@
<?php
class Coords{
private $min = 0;
private $max = 999;
public $x;
public $y;
public function __construct(int $x = 0, int $y = 0) {
if (($x < $this->min) || ($x > $this->max) || ($y < $this->min) || ($y > $this->max)){
//out of limits
return false;
}
$this->x = $x;
$this->y = $y;
}
public function __toString(){
return $this->x.",".$this->y;
}
public function addDirection(Direction $dir){

@ -9,6 +9,9 @@ class Trail {
}
public function last() {
if($this->trail->isEmpty()){
return false;
}
return $this->trail->top();
}
@ -19,9 +22,12 @@ class Trail {
public function add($value) {
if(!$this->trail->isEmpty()) {
if(Trail::kind($this->trail->bottom()) !== Trail::kind($value)) {
throw new TypeError(
'items added to a trail must be of the same kind'
);
//
// throw new TypeError(
// 'items added to a trail must be of the same kind'
// );
return false;
}
if($this->contains($value)) {

@ -123,6 +123,7 @@ class TronGame
}else{
$lastsCells[$botCount] = $this->bots[$botCount]->grow($dir);
if($lastsCells[$botCount] === false){
$loosers[] = $botCount;
$this->bots[$botCount]->loose();
@ -151,8 +152,7 @@ class TronGame
}
}
//loosers list (in order to pass their id)
$loosersList = array();
foreach($loosers as $looser){
@ -173,19 +173,21 @@ class TronGame
$cmh = curl_multi_init();
for ($i = 0; $i < count($iasUrls); $i++){
$data_string = json_encode($postParams[$i]);
$ch[$i] = curl_init($iasUrls[$i]);
curl_setopt($ch[$i], CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch[$i], CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch[$i], CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch[$i], CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch[$i], CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_multi_add_handle($cmh,$ch[$i]);
if(isset($postParams[$i])){ //dont use already deads bots
$data_string = json_encode($postParams[$i]);
$ch[$i] = curl_init($iasUrls[$i]);
curl_setopt($ch[$i], CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch[$i], CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch[$i], CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch[$i], CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch[$i], CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_multi_add_handle($cmh,$ch[$i]);
}
}
//send the requests
@ -195,34 +197,40 @@ class TronGame
//Get results
for ($i = 0; $i < count($iasUrls); $i++){
// Check for errors
$curlError = curl_error($ch[$i]);
if($curlError == "") {
$response = curl_multi_getcontent($ch[$i]);
if(! $arr = json_decode($response,TRUE)){
$arr=array();
}
$res[$i] = array(
'messageSend' => json_encode($postParams[$i]),
'response' => $response,
'httpStatus' => curl_getinfo($ch[$i])['http_code'],
'responseArr' => $arr
);
}else{
$res[$i] = false;
for ($i = 0; $i < count($iasUrls); $i++){
if(isset($postParams[$i])){
// Check for errors
$curlError = curl_error($ch[$i]);
if($curlError == "") {
$response = curl_multi_getcontent($ch[$i]);
if(! $arr = json_decode($response,TRUE)){
$arr=array();
}
$res[$i] = array(
'messageSend' => json_encode($postParams[$i]),
'response' => $response,
'httpStatus' => curl_getinfo($ch[$i])['http_code'],
'responseArr' => $arr
);
}else{
$res[$i] = false;
}
//close
curl_multi_remove_handle($cmh, $ch[$i]);
curl_close($ch[$i]);
}
//close
curl_multi_remove_handle($cmh, $ch[$i]);
curl_close($ch[$i]);
}
// Clean up the curl_multi handle
curl_multi_close($cmh);
return $res;
}
public function init_game(){
public function init_game(){
//send init messages to bots
$logs = "";
$fullLogs = "";
@ -246,7 +254,7 @@ class TronGame
return array($logs,$fullLogs);
}
public function __construct($botsInfos){
public function __construct($botsInfos){
$this->gameId = get_unique_id();
$this->bots = array();
$positions = array();

@ -8,12 +8,19 @@ class TronPlayer{
public $isAlive = true;
public function grow(Direction $dir){
$dest = $this->trail->last()->addDirection($dir);
if($dest == false){
$this->loose();
return false;
}
$this->trail->add($this->trail->last()->addDirection($dir));
return $this->trail->last();
}
public function loose(){
$this->isAlive = false;
$this->trail->emptyTrail();
error_log($this->name." a perdu");
return false;
}
public function make($botId, Coords $initialsCoords,$name,$url){

Loading…
Cancel
Save