3v4l.org

run code in 300+ PHP versions simultaneously
<?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(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), "", "", "")); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pKnSk
function name:  (null)
number of ops:  42
compiled vars:  !0 = $m1, !1 = $m2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'MAXSIZE'
          2        SEND_VAL                                                 100
          3        DO_ICALL                                                 
   42     4        FETCH_CONSTANT                                   ~3      'MAXSIZE'
          5        ECHO                                                     ~3
   43     6        INIT_FCALL                                               'define'
          7        FETCH_CONSTANT                                   ~4      'P1'
          8        SEND_VAL                                                 ~4
          9        SEND_VAL                                                 'r'
         10        DO_ICALL                                                 
   44    11        INIT_FCALL                                               'define'
         12        FETCH_CONSTANT                                   ~6      'P2'
         13        SEND_VAL                                                 ~6
         14        SEND_VAL                                                 'l'
         15        DO_ICALL                                                 
   45    16        INIT_FCALL                                               'define'
         17        FETCH_CONSTANT                                   ~8      'WALL'
         18        SEND_VAL                                                 ~8
         19        SEND_VAL                                                 '%23'
         20        DO_ICALL                                                 
   55    21        INIT_STATIC_METHOD_CALL                                  'Move', 'initializeEmpty'
         22        DO_FCALL                                      0  $10     
         23        ASSIGN                                                   !0, $10
   56    24        NEW                                              $12     'Move'
         25        SEND_VAL_EX                                              <array>
         26        SEND_VAL_EX                                              'RIGHT'
         27        SEND_VAL_EX                                              10
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !1, $12
   57    30        INIT_FCALL                                               'print_r'
         31        INIT_STATIC_METHOD_CALL                                  'Move', 'maxValDirection'
         32        INIT_ARRAY                                       ~15     !0
         33        ADD_ARRAY_ELEMENT                                ~15     !1
         34        SEND_VAL                                                 ~15
         35        SEND_VAL                                                 ''
         36        SEND_VAL                                                 ''
         37        SEND_VAL                                                 ''
         38        DO_FCALL                                      0  $16     
         39        SEND_VAR                                                 $16
         40        DO_ICALL                                                 
   58    41      > RETURN                                                   1

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

End of function nextmove

Class Move:
Function initializeempty:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pKnSk
function name:  initializeEmpty
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     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
   10     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/pKnSk
function name:  __construct
number of ops:  14
compiled vars:  !0 = $pos, !1 = $direction, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   13     3        FETCH_DIM_R                                      ~4      !0, 0
          4        ASSIGN_OBJ                                               'y'
          5        OP_DATA                                                  ~4
   14     6        FETCH_DIM_R                                      ~6      !0, 1
          7        ASSIGN_OBJ                                               'x'
          8        OP_DATA                                                  ~6
   15     9        ASSIGN_OBJ                                               'value'
         10        OP_DATA                                                  !2
   16    11        ASSIGN_OBJ                                               'direction'
         12        OP_DATA                                                  !1
   17    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/pKnSk
function name:  compare
number of ops:  11
compiled vars:  !0 = $move
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     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
   21    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/pKnSk
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
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   24     4        INIT_STATIC_METHOD_CALL                                  'Move', 'initializeEmpty'
          5        DO_FCALL                                      0  $6      
          6        ASSIGN                                                   !4, $6
   25     7      > FE_RESET_R                                       $8      !0, ->19
          8    > > FE_FETCH_R                                               $8, !5, ->19
   26     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          
   27    14        INIT_METHOD_CALL                                         !5, 'compare'
         15        SEND_VAR_EX                                              !4
         16        DO_FCALL                                      0  $10     
         17        ASSIGN                                                   !4, $10
   25    18      > JMP                                                      ->8
         19    >   FE_FREE                                                  $8
   29    20      > RETURN                                                   !4
   30    21*     > RETURN                                                   null

End of function maxvaldirection

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

End of function setvalue

End of class Move.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.74 ms | 1412 KiB | 19 Q