Add MrGameEng.AI utility-AI module; format codebase with CSharpier New MrGameEng.AI module (ResponseCurve, Consideration, UtilityAction, UtilityAi selector, Blackboard) plus CSharpier formatting applied across the whole engine. Documents the CSharpier convention in CLAUDE.md. @
This commit is contained in:
@@ -8,10 +8,7 @@ public class FlowFieldTests
|
||||
[Fact]
|
||||
public void Build_DistancesGrowFromGoal_DirectionsDescend()
|
||||
{
|
||||
var grid = new TestGrid(
|
||||
".....",
|
||||
".###.",
|
||||
".....");
|
||||
var grid = new TestGrid(".....", ".###.", ".....");
|
||||
var builder = new FlowFieldBuilder(grid);
|
||||
var field = new FlowField();
|
||||
|
||||
@@ -25,7 +22,11 @@ public class FlowFieldTests
|
||||
{
|
||||
for (var x = 0; x < grid.Width; x++)
|
||||
{
|
||||
if (!grid.IsPassable(x, y) || !field.IsReachable(x, y) || field.DistanceAt(x, y) == 0f)
|
||||
if (
|
||||
!grid.IsPassable(x, y)
|
||||
|| !field.IsReachable(x, y)
|
||||
|| field.DistanceAt(x, y) == 0f
|
||||
)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -34,8 +35,10 @@ public class FlowFieldTests
|
||||
Assert.NotEqual(Vector2.Zero, direction);
|
||||
var nx = x + Math.Sign(MathF.Round(direction.X * 10f));
|
||||
var ny = y + Math.Sign(MathF.Round(direction.Y * 10f));
|
||||
Assert.True(field.DistanceAt(nx, ny) < field.DistanceAt(x, y),
|
||||
$"direction at ({x},{y}) does not descend");
|
||||
Assert.True(
|
||||
field.DistanceAt(nx, ny) < field.DistanceAt(x, y),
|
||||
$"direction at ({x},{y}) does not descend"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,10 +46,7 @@ public class FlowFieldTests
|
||||
[Fact]
|
||||
public void Build_UnreachablePocket_IsFlagged()
|
||||
{
|
||||
var grid = new TestGrid(
|
||||
"..#..",
|
||||
"..#..",
|
||||
"..#..");
|
||||
var grid = new TestGrid("..#..", "..#..", "..#..");
|
||||
var builder = new FlowFieldBuilder(grid);
|
||||
var field = new FlowField();
|
||||
|
||||
|
||||
@@ -5,9 +5,13 @@ namespace MrGameEng.Pathfinding.Tests;
|
||||
|
||||
public class GridPathfinderTests
|
||||
{
|
||||
private static List<Point> Path(IPathGrid grid, Point start, Point goal,
|
||||
private static List<Point> Path(
|
||||
IPathGrid grid,
|
||||
Point start,
|
||||
Point goal,
|
||||
PathAlgorithm algorithm = PathAlgorithm.AStar,
|
||||
GridConnectivity connectivity = GridConnectivity.Eight)
|
||||
GridConnectivity connectivity = GridConnectivity.Eight
|
||||
)
|
||||
{
|
||||
var pathfinder = new GridPathfinder(grid, connectivity);
|
||||
var path = new List<Point>();
|
||||
@@ -26,7 +30,10 @@ public class GridPathfinderTests
|
||||
{
|
||||
var dx = Math.Abs(path[i].X - path[i - 1].X);
|
||||
var dy = Math.Abs(path[i].Y - path[i - 1].Y);
|
||||
Assert.True(dx <= 1 && dy <= 1 && dx + dy > 0, $"non-adjacent step {path[i - 1]} -> {path[i]}");
|
||||
Assert.True(
|
||||
dx <= 1 && dy <= 1 && dx + dy > 0,
|
||||
$"non-adjacent step {path[i - 1]} -> {path[i]}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,10 +44,7 @@ public class GridPathfinderTests
|
||||
[InlineData(PathAlgorithm.BreadthFirst)]
|
||||
public void FindPath_OpenField_StraightLine(PathAlgorithm algorithm)
|
||||
{
|
||||
var grid = new TestGrid(
|
||||
".....",
|
||||
".....",
|
||||
".....");
|
||||
var grid = new TestGrid(".....", ".....", ".....");
|
||||
|
||||
var path = Path(grid, new Point(0, 1), new Point(4, 1), algorithm);
|
||||
|
||||
@@ -54,10 +58,7 @@ public class GridPathfinderTests
|
||||
[InlineData(PathAlgorithm.BreadthFirst)]
|
||||
public void FindPath_WallsForceDetour(PathAlgorithm algorithm)
|
||||
{
|
||||
var grid = new TestGrid(
|
||||
".....",
|
||||
"####.",
|
||||
".....");
|
||||
var grid = new TestGrid(".....", "####.", ".....");
|
||||
|
||||
var path = Path(grid, new Point(0, 0), new Point(0, 2), algorithm);
|
||||
|
||||
@@ -68,10 +69,7 @@ public class GridPathfinderTests
|
||||
[Fact]
|
||||
public void FindPath_NoRoute_ReturnsFalse()
|
||||
{
|
||||
var grid = new TestGrid(
|
||||
".#.",
|
||||
".#.",
|
||||
".#.");
|
||||
var grid = new TestGrid(".#.", ".#.", ".#.");
|
||||
var pathfinder = new GridPathfinder(grid);
|
||||
var path = new List<Point>();
|
||||
|
||||
@@ -92,9 +90,7 @@ public class GridPathfinderTests
|
||||
[Fact]
|
||||
public void FindPath_DiagonalNeverCutsCorners()
|
||||
{
|
||||
var grid = new TestGrid(
|
||||
".#",
|
||||
"#.");
|
||||
var grid = new TestGrid(".#", "#.");
|
||||
var pathfinder = new GridPathfinder(grid, GridConnectivity.Eight);
|
||||
var path = new List<Point>();
|
||||
|
||||
@@ -105,12 +101,14 @@ public class GridPathfinderTests
|
||||
[Fact]
|
||||
public void FindPath_FourConnectivity_NoDiagonalSteps()
|
||||
{
|
||||
var grid = new TestGrid(
|
||||
"...",
|
||||
"...",
|
||||
"...");
|
||||
var grid = new TestGrid("...", "...", "...");
|
||||
|
||||
var path = Path(grid, new Point(0, 0), new Point(2, 2), connectivity: GridConnectivity.Four);
|
||||
var path = Path(
|
||||
grid,
|
||||
new Point(0, 0),
|
||||
new Point(2, 2),
|
||||
connectivity: GridConnectivity.Four
|
||||
);
|
||||
|
||||
Assert.Equal(5, path.Count); // манхэттен: 4 шага
|
||||
for (var i = 1; i < path.Count; i++)
|
||||
@@ -127,10 +125,7 @@ public class GridPathfinderTests
|
||||
public void FindPath_CostAware_AvoidsExpensiveTerrain(PathAlgorithm algorithm)
|
||||
{
|
||||
// Прямой путь через болото (цена 9) дороже обхода по краю.
|
||||
var grid = new TestGrid(
|
||||
".....",
|
||||
".999.",
|
||||
".....");
|
||||
var grid = new TestGrid(".....", ".999.", ".....");
|
||||
|
||||
var path = Path(grid, new Point(0, 1), new Point(4, 1), algorithm);
|
||||
|
||||
@@ -140,10 +135,7 @@ public class GridPathfinderTests
|
||||
[Fact]
|
||||
public void FindPath_BreadthFirst_IgnoresCosts()
|
||||
{
|
||||
var grid = new TestGrid(
|
||||
".....",
|
||||
".999.",
|
||||
".....");
|
||||
var grid = new TestGrid(".....", ".999.", ".....");
|
||||
|
||||
var path = Path(grid, new Point(0, 1), new Point(4, 1), PathAlgorithm.BreadthFirst);
|
||||
|
||||
@@ -153,10 +145,7 @@ public class GridPathfinderTests
|
||||
[Fact]
|
||||
public void FindPath_ReusedInstance_GivesCleanResults()
|
||||
{
|
||||
var grid = new TestGrid(
|
||||
".....",
|
||||
".###.",
|
||||
".....");
|
||||
var grid = new TestGrid(".....", ".###.", ".....");
|
||||
var pathfinder = new GridPathfinder(grid);
|
||||
var path = new List<Point>();
|
||||
|
||||
@@ -170,12 +159,7 @@ public class GridPathfinderTests
|
||||
[Fact]
|
||||
public void FindPath_AStarMatchesDijkstraCost()
|
||||
{
|
||||
var grid = new TestGrid(
|
||||
"..3..",
|
||||
".#3#.",
|
||||
"..3..",
|
||||
".###.",
|
||||
".....");
|
||||
var grid = new TestGrid("..3..", ".#3#.", "..3..", ".###.", ".....");
|
||||
var start = new Point(0, 0);
|
||||
var goal = new Point(4, 4);
|
||||
|
||||
|
||||
@@ -27,8 +27,9 @@ public class GridResizeTests
|
||||
var pathfinder = new GridPathfinder(grid);
|
||||
grid.Width = 8;
|
||||
|
||||
Assert.Throws<InvalidOperationException>(
|
||||
() => pathfinder.FindPath(new Point(0, 0), new Point(1, 1), []));
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
pathfinder.FindPath(new Point(0, 0), new Point(1, 1), [])
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -38,7 +39,8 @@ public class GridResizeTests
|
||||
var builder = new FlowFieldBuilder(grid);
|
||||
grid.Height = 8;
|
||||
|
||||
Assert.Throws<InvalidOperationException>(
|
||||
() => builder.Build([new Point(0, 0)], new FlowField()));
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
builder.Build([new Point(0, 0)], new FlowField())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
@@ -15,5 +14,4 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\MrGameEng.Pathfinding\MrGameEng.Pathfinding.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user