@ 2015-11-21T10:07:21Z <?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", 100);
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.000 0.043 18.19 5.6.14 0.003 0.043 18.28 5.6.13 0.007 0.077 18.15 5.6.12 0.000 0.053 21.16 5.6.11 0.003 0.053 21.02 5.6.10 0.007 0.080 21.09 5.6.9 0.007 0.063 21.08 5.6.8 0.017 0.070 20.39 5.5.30 0.003 0.063 17.97 5.5.29 0.017 0.070 18.09 5.5.28 0.007 0.060 20.91 5.5.27 0.013 0.037 20.73 5.5.26 0.020 0.070 20.88 5.5.25 0.013 0.073 20.48 5.5.24 0.013 0.053 20.14
preferences:dark mode live preview
141.99 ms | 1394 KiB | 7 Q