Files

24 lines
657 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using MrGameEng.Pathfinding;
namespace MrGameEng.Pathfinding.Tests;
/// <summary>Грид из строк: '#' — стена, '.' — клетка с ценой 1, '2'..'9' — клетка с этой ценой.</summary>
public sealed class TestGrid : IPathGrid
{
private readonly string[] _rows;
public TestGrid(params string[] rows) => _rows = rows;
public int Width => _rows[0].Length;
public int Height => _rows.Length;
public bool IsPassable(int x, int y) => _rows[y][x] != '#';
public float Cost(int x, int y)
{
var cell = _rows[y][x];
return cell is >= '2' and <= '9' ? cell - '0' : 1f;
}
}