@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | { |
21 | 21 | $matrix = $this->convertToMatrix($syntax); |
22 | 22 | |
23 | - foreach($matrix as $x => $line) |
|
23 | + foreach ($matrix as $x => $line) |
|
24 | 24 | { |
25 | - foreach($line as $y => $char) |
|
25 | + foreach ($line as $y => $char) |
|
26 | 26 | { |
27 | 27 | $matrix[$x][$y] = ($char !== self::WALL) ? 1 : 0; |
28 | 28 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | { |
36 | 36 | $matrix = array_filter(explode("\n", $syntax)); |
37 | 37 | |
38 | - foreach($matrix as $key => $line) |
|
38 | + foreach ($matrix as $key => $line) |
|
39 | 39 | { |
40 | 40 | $matrix[$key] = array_filter(str_split($line)); |
41 | 41 | } |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | $syntax = ''; |
49 | 49 | |
50 | 50 | $nodes = $grid->getNodes(); |
51 | - foreach($nodes as $line) |
|
51 | + foreach ($nodes as $line) |
|
52 | 52 | { |
53 | - foreach($line as $node) |
|
53 | + foreach ($line as $node) |
|
54 | 54 | { |
55 | 55 | $syntax .= ($node->isWalkable() ? self::FREE : self::WALL); |
56 | 56 | } |
@@ -65,23 +65,23 @@ discard block |
||
65 | 65 | $syntax = ''; |
66 | 66 | |
67 | 67 | $nodes = $grid->getNodes(); |
68 | - foreach($nodes as $line) |
|
68 | + foreach ($nodes as $line) |
|
69 | 69 | { |
70 | - foreach($line as $node) |
|
70 | + foreach ($line as $node) |
|
71 | 71 | { |
72 | - if(! $node->isWalkable()) |
|
72 | + if (!$node->isWalkable()) |
|
73 | 73 | { |
74 | 74 | $syntax .= self::WALL; |
75 | 75 | } |
76 | - elseif($node->toString() == $path->getStartNode()->toString()) |
|
76 | + elseif ($node->toString() == $path->getStartNode()->toString()) |
|
77 | 77 | { |
78 | 78 | $syntax .= self::IN; |
79 | 79 | } |
80 | - elseif($node->toString() == $path->getEndNode()->toString()) |
|
80 | + elseif ($node->toString() == $path->getEndNode()->toString()) |
|
81 | 81 | { |
82 | 82 | $syntax .= self::OUT; |
83 | 83 | } |
84 | - elseif($path->contains($node)) |
|
84 | + elseif ($path->contains($node)) |
|
85 | 85 | { |
86 | 86 | $syntax .= self::STEP; |
87 | 87 | } |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | public function findAndCreateNode($syntax, $charToFind) |
100 | 100 | { |
101 | 101 | $xCount = count($syntax); |
102 | - for($x = 0; $x < $xCount; $x++) |
|
102 | + for ($x = 0; $x < $xCount; $x++) |
|
103 | 103 | { |
104 | 104 | $yCount = count($syntax[$x]); |
105 | - for($y = 0; $y < $yCount; $y++) |
|
105 | + for ($y = 0; $y < $yCount; $y++) |
|
106 | 106 | { |
107 | - if($syntax[$x][$y] === $charToFind) |
|
107 | + if ($syntax[$x][$y] === $charToFind) |
|
108 | 108 | { |
109 | 109 | return new Node($x, $y); |
110 | 110 | } |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | { |
117 | 117 | $nodes = array(); |
118 | 118 | $xCount = count($syntax); |
119 | - for($x = 0; $x < $xCount; $x++) |
|
119 | + for ($x = 0; $x < $xCount; $x++) |
|
120 | 120 | { |
121 | 121 | $yCount = count($syntax[$x]); |
122 | - for($y = 0; $y < $yCount; $y++) |
|
122 | + for ($y = 0; $y < $yCount; $y++) |
|
123 | 123 | { |
124 | - if($syntax[$x][$y] === $charToFind) |
|
124 | + if ($syntax[$x][$y] === $charToFind) |
|
125 | 125 | { |
126 | 126 | $nodes[] = new Node($x, $y); |
127 | 127 | } |
@@ -135,32 +135,32 @@ discard block |
||
135 | 135 | { |
136 | 136 | $deltas = array( |
137 | 137 | array(-1, -1), array(-1, +0), array(-1, +1), |
138 | - array(+0, -1), array(+0, +1), |
|
138 | + array(+0, -1), array(+0, +1), |
|
139 | 139 | array(+1, -1), array(+1, +0), array(+1, +1), |
140 | 140 | ); |
141 | 141 | |
142 | 142 | $node = $this->findAndCreateNode($matrix, self::IN); |
143 | 143 | $target = $this->findAndCreateNode($matrix, self::OUT); |
144 | 144 | $path = array($node); |
145 | - while($node->getId() !== $target->getId()) |
|
145 | + while ($node->getId() !== $target->getId()) |
|
146 | 146 | { |
147 | 147 | $newNode = null; |
148 | - foreach($deltas as $delta) |
|
148 | + foreach ($deltas as $delta) |
|
149 | 149 | { |
150 | 150 | $x = $node->getX() + $delta[0]; |
151 | 151 | $y = $node->getY() + $delta[1]; |
152 | 152 | |
153 | - if(! array_key_exists($x, $matrix)) |
|
153 | + if (!array_key_exists($x, $matrix)) |
|
154 | 154 | { |
155 | 155 | continue; |
156 | 156 | } |
157 | 157 | |
158 | - if(! array_key_exists($y, $matrix[$x])) |
|
158 | + if (!array_key_exists($y, $matrix[$x])) |
|
159 | 159 | { |
160 | 160 | continue; |
161 | 161 | } |
162 | 162 | |
163 | - if($matrix[$x][$y] === self::STEP || $matrix[$x][$y] === self::OUT) |
|
163 | + if ($matrix[$x][$y] === self::STEP || $matrix[$x][$y] === self::OUT) |
|
164 | 164 | { |
165 | 165 | $matrix[$x][$y] = self::FREE; |
166 | 166 | $newNode = new Node($x, $y); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - if(! $newNode instanceof Node) |
|
171 | + if (!$newNode instanceof Node) |
|
172 | 172 | { |
173 | 173 | throw new \RuntimeException('Path is not continous in the grid'); |
174 | 174 | } |