Ajoute le jour 15

Merci https://github.com/BlackScorp/astar ✌️
This commit is contained in:
2021-12-15 12:38:01 +01:00
parent ec95bf332c
commit 81b4bc585d
31 changed files with 76098 additions and 0 deletions

21
day_15/part_1.php Normal file
View File

@@ -0,0 +1,21 @@
<?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();
}