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();
@ -152,7 +153,6 @@ class TronGame
}
}
//loosers list (in order to pass their id)
$loosersList = array();
foreach($loosers as $looser){
@ -173,6 +173,7 @@ class TronGame
$cmh = curl_multi_init();
for ($i = 0; $i < count($iasUrls); $i++){
if(isset($postParams[$i])){ //dont use already deads bots
$data_string = json_encode($postParams[$i]);
$ch[$i] = curl_init($iasUrls[$i]);
@ -187,6 +188,7 @@ class TronGame
);
curl_multi_add_handle($cmh,$ch[$i]);
}
}
//send the requests
do {
@ -195,7 +197,10 @@ class TronGame
//Get results
for ($i = 0; $i < count($iasUrls); $i++){
if(isset($postParams[$i])){
// Check for errors
$curlError = curl_error($ch[$i]);
if($curlError == "") {
@ -216,6 +221,9 @@ class TronGame
//close
curl_multi_remove_handle($cmh, $ch[$i]);
curl_close($ch[$i]);
}
}
// Clean up the curl_multi handle
curl_multi_close($cmh);

@ -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