3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Pos { var $x; var $y; public function __construct($x, $y){ $this->x = $x; $this->y = $y; } public function distance($pos){ return (abs($this->x - $pos->x) + abs($this->y - $pos->y)); } } 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->y; $this->x = $pos->x; $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[$this->y][$this->x] != CLEAR) $this->value = -10; else{ $this-> value = 1; } } } define("CLEAR", chr(45)); define("P1", chr(114)); define("P2", chr(103)); define("WALL", chr(35)); function nextMove($player,$pos,$board, $opPos){ $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]); } $m1 = Move::initializeEmpty(); $m2 = new Move(array(0, 1), "RIGHT", 10); print_r(Move::maxValDirection(array($m1, $m2), "", "", "")); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EqDLZ
function name:  (null)
number of ops:  37
compiled vars:  !0 = $m1, !1 = $m2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'CLEAR'
          2        SEND_VAL                                                 '-'
          3        DO_ICALL                                                 
   57     4        INIT_FCALL                                               'define'
          5        SEND_VAL                                                 'P1'
          6        SEND_VAL                                                 'r'
          7        DO_ICALL                                                 
   58     8        INIT_FCALL                                               'define'
          9        SEND_VAL                                                 'P2'
         10        SEND_VAL                                                 'g'
         11        DO_ICALL                                                 
   59    12        INIT_FCALL                                               'define'
         13        SEND_VAL                                                 'WALL'
         14        SEND_VAL                                                 '%23'
         15        DO_ICALL                                                 
   75    16        INIT_STATIC_METHOD_CALL                                  'Move', 'initializeEmpty'
         17        DO_FCALL                                      0  $6      
         18        ASSIGN                                                   !0, $6
   76    19        NEW                                              $8      'Move'
         20        SEND_VAL_EX                                              <array>
         21        SEND_VAL_EX                                              'RIGHT'
         22        SEND_VAL_EX                                              10
         23        DO_FCALL                                      0          
         24        ASSIGN                                                   !1, $8
   77    25        INIT_FCALL                                               'print_r'
         26        INIT_STATIC_METHOD_CALL                                  'Move', 'maxValDirection'
         27        INIT_ARRAY                                       ~11     !0
         28        ADD_ARRAY_ELEMENT                                ~11     !1
         29        SEND_VAL                                                 ~11
         30        SEND_VAL                                                 ''
         31        SEND_VAL                                                 ''
         32        SEND_VAL                                                 ''
         33        DO_FCALL                                      0  $12     
         34        SEND_VAR                                                 $12
         35        DO_ICALL                                                 
   78    36      > RETURN                                                   1

Function nextmove:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EqDLZ
function name:  nextMove
number of ops:  83
compiled vars:  !0 = $player, !1 = $pos, !2 = $board, !3 = $opPos, !4 = $moves
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   62     4        ASSIGN                                                   !4, <array>
   63     5        INIT_FCALL                                               'array_push'
          6        SEND_REF                                                 !4
          7        NEW                                              $6      'Move'
          8        NEW                                              $7      'Pos'
          9        CHECK_FUNC_ARG                                           
         10        FETCH_OBJ_FUNC_ARG                               $8      !1, 'x'
         11        SEND_FUNC_ARG                                            $8
         12        FETCH_OBJ_R                                      ~9      !1, 'y'
         13        SUB                                              ~10     ~9, 1
         14        SEND_VAL_EX                                              ~10
         15        DO_FCALL                                      0          
         16        SEND_VAR_NO_REF_EX                                       $7
         17        SEND_VAL_EX                                              'UP'
         18        SEND_VAL_EX                                              -1
         19        DO_FCALL                                      0          
         20        SEND_VAR                                                 $6
         21        DO_ICALL                                                 
   64    22        INIT_FCALL                                               'array_push'
         23        SEND_REF                                                 !4
         24        NEW                                              $14     'Move'
         25        NEW                                              $15     'Pos'
         26        CHECK_FUNC_ARG                                           
         27        FETCH_OBJ_FUNC_ARG                               $16     !1, 'x'
         28        SEND_FUNC_ARG                                            $16
         29        FETCH_OBJ_R                                      ~17     !1, 'y'
         30        ADD                                              ~18     ~17, 1
         31        SEND_VAL_EX                                              ~18
         32        DO_FCALL                                      0          
         33        SEND_VAR_NO_REF_EX                                       $15
         34        SEND_VAL_EX                                              'DOWN'
         35        SEND_VAL_EX                                              -1
         36        DO_FCALL                                      0          
         37        SEND_VAR                                                 $14
         38        DO_ICALL                                                 
   65    39        INIT_FCALL                                               'array_push'
         40        SEND_REF                                                 !4
         41        NEW                                              $22     'Move'
         42        NEW                                              $23     'Pos'
         43        FETCH_OBJ_R                                      ~24     !1, 'x'
         44        SUB                                              ~25     ~24, 1
         45        SEND_VAL_EX                                              ~25
         46        CHECK_FUNC_ARG                                           
         47        FETCH_OBJ_FUNC_ARG                               $26     !1, 'y'
         48        SEND_FUNC_ARG                                            $26
         49        DO_FCALL                                      0          
         50        SEND_VAR_NO_REF_EX                                       $23
         51        SEND_VAL_EX                                              'LEFT'
         52        SEND_VAL_EX                                              -1
         53        DO_FCALL                                      0          
         54        SEND_VAR                                                 $22
         55        DO_ICALL                                                 
   66    56        INIT_FCALL                                               'array_push'
         57        SEND_REF                                                 !4
         58        NEW                                              $30     'Move'
         59        NEW                                              $31     'Pos'
         60        FETCH_OBJ_R                                      ~32     !1, 'x'
         61        ADD                                              ~33     ~32, 1
         62        SEND_VAL_EX                                              ~33
         63        CHECK_FUNC_ARG                                           
         64        FETCH_OBJ_FUNC_ARG                               $34     !1, 'y'
         65        SEND_FUNC_ARG                                            $34
         66        DO_FCALL                                      0          
         67        SEND_VAR_NO_REF_EX                                       $31
         68        SEND_VAL_EX                                              'RIGHT'
         69        SEND_VAL_EX                                              -1
         70        DO_FCALL                                      0          
         71        SEND_VAR                                                 $30
         72        DO_ICALL                                                 
   67    73        INIT_STATIC_METHOD_CALL                                  'Move', 'maxValDirection'
         74        SEND_VAR                                                 !4
         75        SEND_VAR                                                 !2
         76        SEND_VAR                                                 !0
         77        SEND_VAR                                                 !1
         78        SEND_VAR                                                 !3
         79        DO_FCALL                                      0  $38     
         80        FETCH_OBJ_R                                      ~39     $38, 'direction'
         81      > RETURN                                                   ~39
   68    82*     > RETURN                                                   null

End of function nextmove

Function getplayerpos:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 21
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EqDLZ
function name:  getPlayerPos
number of ops:  32
compiled vars:  !0 = $player, !1 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   71     2        INIT_FCALL                                               'ord'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        INIT_FCALL                                               'ord'
          6        FETCH_CONSTANT                                   ~3      'P1'
          7        SEND_VAL                                                 ~3
          8        DO_ICALL                                         $4      
          9        IS_EQUAL                                                 $2, $4
         10      > JMPZ                                                     ~5, ->21
         11    >   NEW                                              $6      'Pos'
         12        CHECK_FUNC_ARG                                           
         13        FETCH_DIM_FUNC_ARG                               $7      !1, 1
         14        SEND_FUNC_ARG                                            $7
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $8      !1, 0
         17        SEND_FUNC_ARG                                            $8
         18        DO_FCALL                                      0          
         19        QM_ASSIGN                                        ~10     $6
         20      > JMP                                                      ->30
         21    >   NEW                                              $11     'Pos'
         22        CHECK_FUNC_ARG                                           
         23        FETCH_DIM_FUNC_ARG                               $12     !1, 3
         24        SEND_FUNC_ARG                                            $12
         25        CHECK_FUNC_ARG                                           
         26        FETCH_DIM_FUNC_ARG                               $13     !1, 2
         27        SEND_FUNC_ARG                                            $13
         28        DO_FCALL                                      0          
         29        QM_ASSIGN                                        ~10     $11
         30    > > RETURN                                                   ~10
   72    31*     > RETURN                                                   null

End of function getplayerpos

Class Pos:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EqDLZ
function name:  __construct
number of ops:  7
compiled vars:  !0 = $x, !1 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        ASSIGN_OBJ                                               'x'
          3        OP_DATA                                                  !0
    9     4        ASSIGN_OBJ                                               'y'
          5        OP_DATA                                                  !1
   10     6      > RETURN                                                   null

End of function __construct

Function distance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EqDLZ
function name:  distance
number of ops:  16
compiled vars:  !0 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'abs'
          2        FETCH_OBJ_R                                      ~1      'x'
          3        FETCH_OBJ_R                                      ~2      !0, 'x'
          4        SUB                                              ~3      ~1, ~2
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        INIT_FCALL                                               'abs'
          8        FETCH_OBJ_R                                      ~5      'y'
          9        FETCH_OBJ_R                                      ~6      !0, 'y'
         10        SUB                                              ~7      ~5, ~6
         11        SEND_VAL                                                 ~7
         12        DO_ICALL                                         $8      
         13        ADD                                              ~9      $4, $8
         14      > RETURN                                                   ~9
   14    15*     > RETURN                                                   null

End of function distance

End of class Pos.

Class Move:
Function initializeempty:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EqDLZ
function name:  initializeEmpty
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   NEW                                              $0      'Move'
          1        SEND_VAL_EX                                              <array>
          2        SEND_VAL_EX                                              'NONE'
          3        SEND_VAL_EX                                              -1
          4        DO_FCALL                                      0          
          5      > RETURN                                                   $0
   25     6*     > RETURN                                                   null

End of function initializeempty

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EqDLZ
function name:  __construct
number of ops:  14
compiled vars:  !0 = $pos, !1 = $direction, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   28     3        FETCH_OBJ_R                                      ~4      !0, 'y'
          4        ASSIGN_OBJ                                               'y'
          5        OP_DATA                                                  ~4
   29     6        FETCH_OBJ_R                                      ~6      !0, 'x'
          7        ASSIGN_OBJ                                               'x'
          8        OP_DATA                                                  ~6
   30     9        ASSIGN_OBJ                                               'value'
         10        OP_DATA                                                  !2
   31    11        ASSIGN_OBJ                                               'direction'
         12        OP_DATA                                                  !1
   32    13      > RETURN                                                   null

End of function __construct

Function compare:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EqDLZ
function name:  compare
number of ops:  11
compiled vars:  !0 = $move
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        FETCH_OBJ_R                                      ~1      !0, 'value'
          2        FETCH_OBJ_R                                      ~2      'value'
          3        IS_SMALLER                                               ~2, ~1
          4      > JMPZ                                                     ~3, ->7
          5    >   QM_ASSIGN                                        ~4      !0
          6      > JMP                                                      ->9
          7    >   FETCH_THIS                                       ~5      
          8        QM_ASSIGN                                        ~4      ~5
          9    > > RETURN                                                   ~4
   36    10*     > RETURN                                                   null

End of function compare

Function maxvaldirection:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 21
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 21
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/EqDLZ
function name:  maxValDirection
number of ops:  24
compiled vars:  !0 = $moves, !1 = $board, !2 = $player, !3 = $pos, !4 = $opPos, !5 = $best, !6 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
   39     5        INIT_STATIC_METHOD_CALL                                  'Move', 'initializeEmpty'
          6        DO_FCALL                                      0  $7      
          7        ASSIGN                                                   !5, $7
   40     8      > FE_RESET_R                                       $9      !0, ->21
          9    > > FE_FETCH_R                                               $9, !6, ->21
   41    10    >   INIT_METHOD_CALL                                         !6, 'setValue'
         11        SEND_VAR_EX                                              !1
         12        SEND_VAR_EX                                              !2
         13        SEND_VAR_EX                                              !3
         14        SEND_VAR_EX                                              !4
         15        DO_FCALL                                      0          
   42    16        INIT_METHOD_CALL                                         !6, 'compare'
         17        SEND_VAR_EX                                              !5
         18        DO_FCALL                                      0  $11     
         19        ASSIGN                                                   !5, $11
   40    20      > JMP                                                      ->9
         21    >   FE_FREE                                                  $9
   44    22      > RETURN                                                   !5
   45    23*     > RETURN                                                   null

End of function maxvaldirection

Function setvalue:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EqDLZ
function name:  setValue
number of ops:  17
compiled vars:  !0 = $board, !1 = $player, !2 = $pos, !3 = $opPos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   48     4        FETCH_OBJ_R                                      ~4      'y'
          5        FETCH_OBJ_R                                      ~6      'x'
          6        FETCH_DIM_R                                      ~5      !0, ~4
          7        FETCH_DIM_R                                      ~7      ~5, ~6
          8        FETCH_CONSTANT                                   ~8      'CLEAR'
          9        IS_NOT_EQUAL                                             ~7, ~8
         10      > JMPZ                                                     ~9, ->14
   49    11    >   ASSIGN_OBJ                                               'value'
         12        OP_DATA                                                  -10
         13      > JMP                                                      ->16
   51    14    >   ASSIGN_OBJ                                               'value'
         15        OP_DATA                                                  1
   53    16    > > RETURN                                                   null

End of function setvalue

End of class Move.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
188.99 ms | 1420 KiB | 23 Q