What I need?
I want in PHP a function or class / method that returns an array of the generation path in a grid (9x9), see (code: grid with path). This condition:
- The block cannot overlap
- There is a directional path (see below: What did I have? ). This path may be random and guidance is required.
- You can exit on the right / top and continue the path on the left / bottom (see example below). It is also possible and vice versa.
- The number of steps is variable and cannot overlap with each other.
- Returns an array (code: grid with contour). I need the coordinates from the orange dots in the example image below. In fact, these are the coordinates in the sequence in the array (from orange). But if itβs easier to use a full grid of 9x9 arrays, that's all right.
What did I have?
- Array of an empty grid (code: empty grid):
- Starting position random (see "Start" in the example image)
- The direction in this case is 1234123 (it can be different) (1: up, 2: right, 3: down, 4: left)
Need more info?
If you need more information or something is unclear? please ask me. Thanks!
code: empty grid:
array( array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), )
code: grid with contour (1 = start, 8 = end):
array( array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(0, 0, 0, 0, 3, 0, 2, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(6, 0, 0, 7, 0, 0, 0, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), array(0, 0, 0, 8, 0, 0, 1, 0, 0), array(5, 0, 0, 0, 4, 0, 0, 0, 0), array(0, 0, 0, 0, 0, 0, 0, 0, 0), )
