public function convertToSyntaxWithPath(NodeGrid $grid, NodePath $path) { $syntax = ''; $nodes = $grid->getNodes(); foreach ($nodes as $line) { foreach ($line as $node) { if (!$node->isWalkable()) { $syntax .= self::WALL; } elseif ($node->toString() == $path->getStartNode()->toString()) { $syntax .= self::IN; } elseif ($node->toString() == $path->getEndNode()->toString()) { $syntax .= self::OUT; } elseif ($path->contains($node)) { $syntax .= self::STEP; } else { $syntax .= self::FREE; } } $syntax .= "\n"; } return $syntax; }
/** * @dataProvider providerExemples */ public function testConvertToGrid($syntax, NodeGrid $expectedGrid) { $converter = new ASCIISyntax(); $grid = $converter->convertToGrid($syntax); $this->assertSame(json_encode($expectedGrid->getNodes()), json_encode($grid->getNodes())); }
public function setGrid(NodeGrid $grid) { $this->grid = $grid; $this->distanceGraph = new NodeGraph($grid->buildWalkableNodesList(), false); }