3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo PHP_INT_MIN; echo PHP_INT_MIN * -1; class Cell { var $pos; var $val; public function __construct($pos, $val){ $this->pos = $pos; $this->val = $val; } } class Board { var $cells; public function __construct($raw_array){ $this->cells = array(); $i = 0; foreach($raw_array as $row){ $j = 0; $this->cells[$i] = array(); foreach(str_split($row) as $cell){ $this->cells[$i][$j] = new Cell(new Pos($i, $j), $cell); } } } } class Pos { var $x; var $y; public function __construct($x, $y){ $this->x = $x; $this->y = $y; } public function dist($pos){ return (sqrt(pow($this->x - $pos->x, 2) + pow($this->y - $pos-> y, 2))); } } class Move { var $direction; var $value; var $pos; public static function initializeEmpty(){ return (new Move(array(0, 0), "NONE", -1)); } public function __construct($pos, $direction, $value){ $this->pos = $pos; $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, $opPos){ $best = Move::initializeEmpty(); foreach($moves as $m){ $m->setValue($board, $player, $pos, $opPos); $best = $m->compare($best); } return $best; } public function setValue($board, $player, $pos, $opPos){ if ($board->cells[$this->pos->y][$this->pos->x] != CLEAR) $this->value = -10; else{ if ($this->pos->dist($opPos) == 1){ $this->value = 1; } else{ $this->value = 2; } } } } define("CLEAR", chr(45)); define("P1", chr(114)); define("P2", chr(103)); define("WALL", chr(35)); function nextMove($player, $pos, $opPos, $board){ $moves = array(); array_push($moves, new Move(new Pos($pos->x, $pos->y - 1), "UP", -1)); array_push($moves, new Move(new Pos($pos->x, $pos->y + 1), "DOWN", -1)); array_push($moves, new Move(new Pos($pos->x - 1, $pos->y), "LEFT", -1)); array_push($moves, new Move(new Pos($pos->x + 1, $pos->y), "RIGHT", -1)); return Move::maxValDirection($moves, $board, $player, $pos, $opPos)->direction; } function getPlayerPos($player, $pos){ return ord($player) == ord(P1) ? new Pos($pos[1], $pos[0]) : new Pos($pos[3], $pos[2]); } $fp = fopen("php://stdin", "r"); $player = fgets($fp); //echo $player; $pos = trim(fgets($fp)); $pos = split(' ', $pos); $playerPos = getPlayerPos($player, $pos); $opPos = getPlayerPos(ord($player) == ord(P1) ? P2 : P1, $pos); $board = array(); for ($i=0; $i<15; $i++) { fscanf($fp, "%s", $board[$i]); } print_r($board); $board = new Board($board); print_r($board); $move = nextMove($player,$playerPos,$opPos, $board); echo $move; ?>
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
-92233720368547758089.2233720368548E+18 Fatal error: Uncaught Error: Call to undefined function split() in /in/eW0SX:109 Stack trace: #0 {main} thrown in /in/eW0SX on line 109
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
Notice: Use of undefined constant PHP_INT_MIN - assumed 'PHP_INT_MIN' in /in/eW0SX on line 2 PHP_INT_MIN Notice: Use of undefined constant PHP_INT_MIN - assumed 'PHP_INT_MIN' in /in/eW0SX on line 3 0 Deprecated: Function split() is deprecated in /in/eW0SX on line 109 Notice: Undefined offset: 3 in /in/eW0SX on line 101 Notice: Undefined offset: 2 in /in/eW0SX on line 101 Notice: Undefined offset: 1 in /in/eW0SX on line 101 Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => ) Board Object ( [cells] => Array ( [0] => Array ( [0] => Cell Object ( [pos] => Pos Object ( [x] => 0 [y] => 0 ) [val] => ) ) ) ) Notice: Undefined offset: -1 in /in/eW0SX on line 73 Notice: Undefined offset: 1 in /in/eW0SX on line 73 Notice: Undefined index: in /in/eW0SX on line 73 Notice: Undefined index: in /in/eW0SX on line 73 NONE

preferences:
197.64 ms | 405 KiB | 225 Q