Beispiel #1
0
        public void FindsFirstTarget()
        {
            var search = new AStarSearch <int>(EqualityComparer <int> .Default, InfiniteExpander);
            var result = search.FindFirst(1, x => x == 192, GrowHeuristic);

            Assert.AreEqual(1, result.Steps.First());
            Assert.AreEqual(192, result.Steps.Last());
            Assert.AreEqual(6, result.Length);
            Assert.AreEqual(5 + 1.8, result.Cost, 1e-6f);
        }
Beispiel #2
0
        public override async ValueTask <string> Solve_1()
        {
            var dest      = _grid.BottomRight;
            var s         = new AStarSearch <Point>(null, Expand);
            var path      = s.FindFirst(new Point(0, 0), x => x == dest, x => x.ManhattanDistTo(dest)) !;
            var totalRisk = path.Cost;

            return(totalRisk.ToString());

            IEnumerable <(Point node, float cost)> Expand(Point p)
            {
                foreach (var n in _grid.Get4NeighborsOf(p))
                {
                    yield return(n, _grid[n] - '0');