Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Given a 2D array, it stores the connective data between each area
- * the structure of this array will be $node[MAPID][DIRECTION] = AREAID
- * 1. directions: 0=Up, 1=Right, 2=Down, 3=Left
- * 2. when AREAID is 0, it means that there's no area this direction is connected to
- *
- * A map consists of multiple areas, different maps cannot access each other
- * (e.g areas under Map 1 do not connect to the areas under Map 2)
- *
- * Example input:
- * $nodes = [
- * 1 => [ 2, 5, 0, 0], // up = area 2, right = area 5
- * 2 => [ 3, 0, 1, 6], // up = area 3, down = area 1, left = area 6
- * 3 => [ 0, 4, 2, 0], // ...and so on
- * 4 => [ 0, 0, 0, 3],
- * 5 => [ 0, 0, 0, 1],
- * 6 => [ 0, 2, 7, 0],
- * 7 => [ 6, 0, 8, 0],
- * 8 => [ 7, 9, 0, 0],
- * 9 => [ 0, 0, 0, 8],
- * 10 => [ 0, 0, 0, 11], // area 10, 11 and 12 does not connect to 1-9,
- * 11 => [ 0, 10, 12, 0], // and they are connected to each other, therefore
- * 12 => [11, 0, 0, 0] // this is count as a new map
- * ]
- *
- * 1. You will need to generate an array to store map structure from $nodes,
- * for example the example $nodes will generate the following array:
- * [[[0, 3, 4],
- * [6, 2, 0],
- * [7, 1, 5],
- * [8, 9, 0]],
- * [[11, 10],
- * [12, 0]]]
- *
- * 2. Use this array to generate an output (order doesn't matter):
- * Map 0
- * 03==04
- * ||
- * 06==02
- * || ||
- * 07 01==05
- * ||
- * 08==09
- *
- * Map 1
- * 11==10
- * ||
- * 12
- */
- const DIR_UP = 0;
- const DIR_RIGHT = 1;
- const DIR_DOWN = 2;
- const DIR_LEFT = 3;
- $nodes = [
- 1 => [ 2, 5, 0, 0],
- 2 => [ 3, 0, 1, 6],
- 3 => [ 0, 4, 2, 0],
- 4 => [ 0, 0, 0, 3],
- 5 => [ 0, 0, 0, 1],
- 6 => [ 0, 2, 7, 0],
- 7 => [ 6, 0, 8, 0],
- 8 => [ 7, 9, 0, 0],
- 9 => [ 0, 0, 0, 8],
- 10 => [ 0, 0, 0, 11],
- 11 => [ 0, 10, 12, 0],
- 12 => [11, 0, 0, 0]
- ];
Advertisement
Add Comment
Please, Sign In to add comment