@ 2015-11-21T10:05:34Z <?php
class Move {
var $direction;
var $value;
var $x;
var $y;
public static function initializeEmpty(){
return (new Move(array(0, 0), "NONE", -1));
}
public function __construct($pos, $direction, $value){
$this->y = $pos[0];
$this->x = $pos[1];
$this->value = $value;
$this->direction = $direction;
}
public function compare($move){
return $move->value > $this->value ? $move : $this;
}
public static function maxValDirection($moves, $board, $player, $pos){
$best = Move::initializeEmpty();
foreach($moves as $m){
$m->setValue($board, $player, $pos);
$best = $m->compare($best);
}
return $best;
}
public function setValue($board, $player, $pos){
echo "0";
if ($board[$y][$x] != "-")
$this->value = -1;
else
$this->value = 1;
}
}
define("MAXSIZE", 100);
echo MAXSIZE;
define("EMPTY", '-');
echo EMPTY;
define(P1, "r");
define(P2, "l");
define(WALL, "#");
function nextMove($player,$pos,$board){
$moves = array();
array_push($moves, new Move(array($pos[0] - 1, $pos[1]), "UP", -1));
array_push($moves, new Move(array($pos[0] + 1, $pos[1]), "DOWN", -1));
array_push($moves, new Move(array($pos[0], $pos[1] - 1), "LEFT", -1));
array_push($moves, new Move(array($pos[0], $pos[1] + 1), "RIGHT", -1));
return Move::maxValDirection($moves, $board, $player, $pos)->direction;
}
$m1 = Move::initializeEmpty();
$m2 = new Move(array(0, 1), "RIGHT", 10);
print_r(Move::maxValDirection(array($m1, $m2), "", "", ""));
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.6.15 0.003 0.037 18.16 5.6.14 0.007 0.080 18.28 5.6.13 0.010 0.060 18.27 5.6.12 0.010 0.040 21.02 5.6.11 0.013 0.047 20.95 5.6.10 0.013 0.067 20.97 5.6.9 0.010 0.077 21.11 5.6.8 0.000 0.087 20.38 5.5.30 0.007 0.060 18.02 5.5.29 0.003 0.060 17.95 5.5.28 0.010 0.040 20.76 5.5.27 0.007 0.090 20.74 5.5.26 0.020 0.067 20.81 5.5.25 0.007 0.080 20.68 5.5.24 0.017 0.040 20.18
preferences:dark mode live preview
145.14 ms | 1394 KiB | 7 Q