Hoping to find a way to do this to help streamline the code and make it easy to maintain/read:
if, in the material.inc.php, I have this (this is from Chess game, defining how a piece moves):
Is there a way of building it by defining the types of moves first, such as:
?? I tried exactly that, but it of course fails .. so wondering if this is even possible, and if so, what's the syntax for it?
if, in the material.inc.php, I have this (this is from Chess game, defining how a piece moves):
Code: Select all
$this->gameMaterial = array(
1 => array(
"moveMatrixByPlayerAndSymbol" => array(
1 => array(
"rook" => array(
array("x" => 0, "y" => 1 ), array("x" => 0, "y" => -1 ), array("x" => 1, "y" => 0 ), array("x" => -1, "y" => 0 ),
array("x" => 0, "y" => 2 ), array("x" => 0, "y" => -2 ), array("x" => 2, "y" => 0 ), array("x" => -2, "y" => 0 ),
array("x" => 0, "y" => 3 ), array("x" => 0, "y" => -3 ), array("x" => 3, "y" => 0 ), array("x" => -3, "y" => 0 ),
array("x" => 0, "y" => 4 ), array("x" => 0, "y" => -4 ), array("x" => 4, "y" => 0 ), array("x" => -4, "y" => 0 ),
array("x" => 0, "y" => 5 ), array("x" => 0, "y" => -5 ), array("x" => 5, "y" => 0 ), array("x" => -5, "y" => 0 ),
array("x" => 0, "y" => 6 ), array("x" => 0, "y" => -6 ), array("x" => 6, "y" => 0 ), array("x" => -6, "y" => 0 ),
array("x" => 0, "y" => 7 ), array("x" => 0, "y" => -7 ), array("x" => 7, "y" => 0 ), array("x" => -7, "y" => 0 ),
),
"knight" => array(
... etc
Code: Select all
$this->pcOrthogonal = array (
array("x" => 0, "y" => 1 ), array("x" => 0, "y" => -1 ), array("x" => 1, "y" => 0 ), array("x" => -1, "y" => 0 ),
array("x" => 0, "y" => 2 ), array("x" => 0, "y" => -2 ), array("x" => 2, "y" => 0 ), array("x" => -2, "y" => 0 ),
array("x" => 0, "y" => 3 ), array("x" => 0, "y" => -3 ), array("x" => 3, "y" => 0 ), array("x" => -3, "y" => 0 ),
array("x" => 0, "y" => 4 ), array("x" => 0, "y" => -4 ), array("x" => 4, "y" => 0 ), array("x" => -4, "y" => 0 ),
array("x" => 0, "y" => 5 ), array("x" => 0, "y" => -5 ), array("x" => 5, "y" => 0 ), array("x" => -5, "y" => 0 ),
array("x" => 0, "y" => 6 ), array("x" => 0, "y" => -6 ), array("x" => 6, "y" => 0 ), array("x" => -6, "y" => 0 ),
array("x" => 0, "y" => 7 ), array("x" => 0, "y" => -7 ), array("x" => 7, "y" => 0 ), array("x" => -7, "y" => 0 ),
);
$this->pcDiagonal = array ( .... build it similar );
$this->gameMaterial = array(
1 => array(
"moveMatrixByPlayerAndSymbol" => array(
1 => array(
"rook" => array(
$this->pcOrthogonal
),
"queen" => array(
$this->pcOrthogonal,
$this->pcDiagonal,
),
...