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; } } 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){ 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){ $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)->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/Kkrt6
function name:  (null)
number of ops:  37
compiled vars:  !0 = $m1, !1 = $m2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'CLEAR'
          2        SEND_VAL                                                 '-'
          3        DO_ICALL                                                 
   52     4        INIT_FCALL                                               'define'
          5        SEND_VAL                                                 'P1'
          6        SEND_VAL                                                 'r'
          7        DO_ICALL                                                 
   53     8        INIT_FCALL                                               'define'
          9        SEND_VAL                                                 'P2'
         10        SEND_VAL                                                 'g'
         11        DO_ICALL                                                 
   54    12        INIT_FCALL                                               'define'
         13        SEND_VAL                                                 'WALL'
         14        SEND_VAL                                                 '%23'
         15        DO_ICALL                                                 
   71    16        INIT_STATIC_METHOD_CALL                                  'Move', 'initializeEmpty'
         17        DO_FCALL                                      0  $6      
         18        ASSIGN                                                   !0, $6
   72    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
   73    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                                                 
   74    36      > RETURN                                                   1

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

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/Kkrt6
function name:  initializeEmpty
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     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
   21     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/Kkrt6
function name:  __construct
number of ops:  14
compiled vars:  !0 = $pos, !1 = $direction, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   24     3        FETCH_DIM_R                                      ~4      !0, 0
          4        ASSIGN_OBJ                                               'y'
          5        OP_DATA                                                  ~4
   25     6        FETCH_DIM_R                                      ~6      !0, 1
          7        ASSIGN_OBJ                                               'x'
          8        OP_DATA                                                  ~6
   26     9        ASSIGN_OBJ                                               'value'
         10        OP_DATA                                                  !2
   27    11        ASSIGN_OBJ                                               'direction'
         12        OP_DATA                                                  !1
   28    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/Kkrt6
function name:  compare
number of ops:  11
compiled vars:  !0 = $move
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   31     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
   32    10*     > RETURN                                                   null

End of function compare

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

End of function maxvaldirection

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

End of function setvalue

End of class Move.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
206.23 ms | 1416 KiB | 21 Q