dooooooduo

baka

Jan 24th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Given a 2D array, it stores the connective data between each area
  5.  * the structure of this array will be $node[MAPID][DIRECTION] = AREAID
  6.  *      1. directions: 0=Up, 1=Right, 2=Down, 3=Left
  7.  *      2. when AREAID is 0, it means that there's no area this direction is connected to
  8.  *
  9.  * A map consists of multiple areas, different maps cannot access each other
  10.  * (e.g areas under Map 1 do not connect to the areas under Map 2)
  11.  *
  12.  * Example input:
  13.  * $nodes = [
  14.  *      1  => [ 2,  5,  0,  0], // up = area 2, right = area 5
  15.  *      2  => [ 3,  0,  1,  6], // up = area 3, down = area 1, left = area 6
  16.  *      3  => [ 0,  4,  2,  0], // ...and so on
  17.  *      4  => [ 0,  0,  0,  3],
  18.  *      5  => [ 0,  0,  0,  1],
  19.  *      6  => [ 0,  2,  7,  0],
  20.  *      7  => [ 6,  0,  8,  0],
  21.  *      8  => [ 7,  9,  0,  0],
  22.  *      9  => [ 0,  0,  0,  8],
  23.  *      10 => [ 0,  0,  0, 11], // area 10, 11 and 12 does not connect to 1-9,
  24.  *      11 => [ 0, 10, 12,  0], // and they are connected to each other, therefore
  25.  *      12 => [11,  0,  0,  0]  // this is count as a new map
  26.  * ]
  27.  *
  28.  * 1. You will need to generate an array to store map structure from $nodes,
  29.  *    for example the example $nodes will generate the following array:
  30.  * [[[0, 3, 4],
  31.  *   [6, 2, 0],
  32.  *   [7, 1, 5],
  33.  *   [8, 9, 0]],
  34.  *  [[11, 10],
  35.  *   [12,  0]]]
  36.  *
  37.  * 2. Use this array to generate an output (order doesn't matter):
  38.  *  Map 0
  39.  *      03==04
  40.  *      ||    
  41.  *  06==02    
  42.  *  ||  ||    
  43.  *  07  01==05
  44.  *  ||        
  45.  *  08==09    
  46.  *
  47.  *  Map 1
  48.  *  11==10
  49.  *  ||    
  50.  *  12
  51.  */
  52.  
  53. const DIR_UP    = 0;
  54. const DIR_RIGHT = 1;
  55. const DIR_DOWN  = 2;
  56. const DIR_LEFT  = 3;
  57.  
  58. $nodes = [
  59.     1  => [ 2,  5,  0,  0],
  60.     2  => [ 3,  0,  1,  6],
  61.     3  => [ 0,  4,  2,  0],
  62.     4  => [ 0,  0,  0,  3],
  63.     5  => [ 0,  0,  0,  1],
  64.     6  => [ 0,  2,  7,  0],
  65.     7  => [ 6,  0,  8,  0],
  66.     8  => [ 7,  9,  0,  0],
  67.     9  => [ 0,  0,  0,  8],
  68.     10 => [ 0,  0,  0, 11],
  69.     11 => [ 0, 10, 12,  0],
  70.     12 => [11,  0,  0,  0]
  71. ];
Advertisement
Add Comment
Please, Sign In to add comment