advent_of_code_2021/day_15/part_1.php

22 lines
603 B
PHP
Raw Normal View History

<?php
$map = array_map('str_split', explode("\n", file_get_contents('./input.txt')));
include_once './vendor/autoload.php';
$grid = new BlackScorp\Astar\Grid($map);
$startPosition = $grid->getPoint(0, 0);
$endPosition = $grid->getPoint(count($map) - 1, count($map[0]) - 1);
$astar = new BlackScorp\Astar\Astar($grid);
$nodes = $astar->search($startPosition,$endPosition);
if(count($nodes) === 0){
echo "Path not found";
}else{
foreach($nodes as $node){
echo sprintf('%s / %s : %s %s', $node->getX(), $node->getY(), $node->getScore(), "\n");
}
echo $node->getTotalScore();
}