feat: model battlefield terrain and movement costs

This commit is contained in:
Keith Solomon
2026-07-04 15:08:40 -05:00
parent 7b82adbd71
commit 189be5bc64
4 changed files with 203 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace BattleForge\Tests\Unit\Domain;
use BattleForge\Domain\Battlefield;
use BattleForge\Domain\Position;
use BattleForge\Domain\Terrain;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
final class BattlefieldTest extends TestCase
{
public function testItRejectsDimensionsOutsideTheSupportedRange(): void
{
$this->expectException(InvalidArgumentException::class);
new Battlefield(7, 16);
}
public function testItFindsReachableTilesUsingTerrainCostsAndObstacles(): void
{
$battlefield = new Battlefield(8, 8, [
'1:0' => Terrain::Forest,
'0:1' => Terrain::Rough,
'2:0' => Terrain::Water,
'1:1' => Terrain::Blocking,
]);
$reachable = $battlefield->reachable(
new Position(0, 0),
2,
[new Position(0, 2)],
);
self::assertSame(0, $reachable['0:0']);
self::assertSame(2, $reachable['1:0']);
self::assertSame(2, $reachable['0:1']);
self::assertArrayNotHasKey('2:0', $reachable);
self::assertArrayNotHasKey('1:1', $reachable);
self::assertArrayNotHasKey('0:2', $reachable);
}
}