Пример #1
0
        public static Map<float> CalculateWeightings(StaticMaps input)
        {
            const float goal = 999;
            const float cornergoal = 1.2f;
            var res = input.GoalMap.ToMap(goal, 0);

            foreach (var corner in input.CornerMap.TruePositions())
            {
                if (res[corner] > 0) res[corner] *= cornergoal;
            }

            res = AverageOver(res, input.FloorMap, input.GoalMap);
            foreach (var dead in input.DeadMap.TruePositions())
            {
                res[dead] = -1;
            }
            return res;
        }
Пример #2
0
        public static bool DynamicCheck(StaticMaps staticMaps, IStateMaps node)
        {
            var both = staticMaps.WallMap.BitwiseOR(node.CrateMap);

            // Box Rule
            foreach (var crate in node.CrateMap.TruePositions())
            {
                if (staticMaps.GoalMap[crate]) continue;

                if (both[crate + VectorInt2.Left] &&
                    both[crate + VectorInt2.Left + VectorInt2.Down] &&
                    both[crate + VectorInt2.Down]
                    )
                {
                    return true;
                }

                if (both[crate + VectorInt2.Left] &&
                    both[crate + VectorInt2.Left + VectorInt2.Up] &&
                    both[crate + VectorInt2.Up]
                    )
                {
                    return true;
                }

                if (both[crate + VectorInt2.Right] &&
                   both[crate + VectorInt2.Right + VectorInt2.Down] &&
                   both[crate + VectorInt2.Down]
                   )
                {
                    return true;
                }

                if (both[crate + VectorInt2.Right] &&
                    both[crate + VectorInt2.Right + VectorInt2.Up] &&
                    both[crate + VectorInt2.Up]
                    )
                {
                    return true;
                }
            }

            return false;
        }
Пример #3
0
        public void CaseA()
        {
            var report = new TestReport();

            var sample = new Puzzle(new string[]
            {
                "#############",
                "#a ###    b##",
                "# A######  ##",
                "#  ######B ##",
                "#########  ##",
                "#############",
            });

            var boundry = sample.ToMap('#', 'A', 'B' );

            var staticMaps = new StaticMaps()
            {
                FloorMap = sample.ToMap(' ', 'a', 'b'),
                WallMap = sample.ToMap('#')
            };
            var stateMaps = new StateMaps()
            {
                CrateMap = sample.ToMap('A', 'B'),
                MoveMap = FloodFill.Fill(staticMaps.WallMap, sample.First(x => x.State == 'a').Position)
            };

            var pushMap = PushMap.Find(staticMaps, stateMaps, sample.First(x => x.State == 'A').Position, sample.First(x => x.State == 'a').Position);

            report.WriteLine(pushMap);

            Assert.That(report, Is.EqualTo(new TestReport(
            @".............
            ..X..........
            .............
            ..X..........
            .............
            ............."
                )));
        }
Пример #4
0
        public static IBitmap FindDeadMap(StaticMaps staticMaps)
        {
            var dead = new Bitmap(staticMaps.FloorMap.Size);

            // All corners are dead (provided no goals)
            foreach (var corner in staticMaps.CornerMap.TruePositions())
            {
                if (!staticMaps.GoalMap[corner]) dead[corner] = true;
            }

            // All recesses are dead (provided no goals)
            foreach (var recess in staticMaps.RecessMap)
            {
                if (!recess.Intersects(staticMaps.GoalMap))
                {
                    foreach (var cc in recess.TruePositions())
                    {
                        dead[cc] = true;
                    }
                }
            }

            return dead;
        }
Пример #5
0
        public void OverAndBackAgain()
        {
            var report = new TestReport();

            var sample = new Puzzle(new string[]
            {
                "#############",
                "#...........#",
                "#...........#",
                "#...........#",
                "######.######",
                "#......x....#",
                "#o.........p#",
                "#############",
            });

            var staticMaps = new StaticMaps()
            {
                FloorMap = sample.ToMap('.', 'x','o', 'p'),
                WallMap = sample.ToMap('#')
            };

            var crate = sample.ToMap('X', 'x');
            var stateMaps = new StateMaps()
            {
                CrateMap = crate,
                MoveMap = FloodFill.Fill(staticMaps.WallMap.BitwiseOR(crate), sample.First(x => x.State == 'p').Position)
            };

            var from = sample.First(x => x.State == 'x').Position;
            var to = sample.First(x => x.State == 'p').Position;
            var pushMap = PushMap.Find(staticMaps, stateMaps, from, to);
            report.WriteLine(pushMap);

            Assert.That(report, Is.EqualTo(new TestReport(
            @".............
            .XXXXXXXXXXX.
            .XXXXXXXXXXX.
            .XXXXXXXXXXX.
            ......X......
            .XXXXXXXXXXX.
            .XXXXXXXXXXX.
            .............
            "
                )));

            var playerRoute = pushMap.FindPlayerWalkRoute(to);
            report.WriteLine("pushMap.FindPlayerWalkRoute(to)");
            report.WriteLine(playerRoute);

            var crateRoute = pushMap.FindCrateRoute(to);
            report.WriteLine("pushMap.FindCrateRoute(to)");
            report.WriteLine(crateRoute);
        }
Пример #6
0
        public void MultipleCrates()
        {
            var report = new TestReport();

            var sample = new Puzzle(new string[]
            {
                "#############",
                "#   x     p##",
                "#x         ##",
                "#  ######X ##",
                "#########  ##",
                "#############",
            });

            var staticMaps = new StaticMaps()
            {
                FloorMap = sample.ToMap(' ', 'x', 'X', 'p'),
                WallMap = sample.ToMap('#')
            };

            var crate = sample.ToMap('X', 'x');
            var stateMaps = new StateMaps()
            {
                CrateMap = crate,
                MoveMap = FloodFill.Fill(staticMaps.WallMap.BitwiseOR(crate), sample.First(x => x.State == 'p').Position)
            };

            var pushMap = PushMap.Find(staticMaps, stateMaps, sample.First(x => x.State == 'X').Position, sample.First(x => x.State == 'p').Position);

            report.WriteLine(pushMap);

            Assert.That(report, Is.EqualTo(new TestReport(
            @".............
            .....XXXXXX..
            ..XXXXXXXXX..
            ..X......XX..
            .........XX..
            .............
            "
                )));
        }
Пример #7
0
        public void CaseB_WithPath()
        {
            var report = new TestReport();

            var sample = new Puzzle(new string[]
            {
                "#############",
                "#a ###    b##",
                "# A######  ##",
                "#  ######B ##",
                "#########  ##",
                "#############",
            });

            var staticMaps = new StaticMaps()
            {
                FloorMap = sample.ToMap(' ', 'a', 'b'),
                WallMap = sample.ToMap('#')
            };
            var stateMaps = new StateMaps()
            {
                CrateMap = sample.ToMap('A', 'B'),
                MoveMap = FloodFill.Fill(staticMaps.WallMap, sample.First(x => x.State == 'b').Position)
            };

            var pushMap = PushMap.Find(staticMaps, stateMaps, sample.First(x => x.State == 'B').Position, sample.First(x => x.State == 'b').Position);

            report.WriteLine(pushMap);

            var path = pushMap.FindPlayerWalkRoute(new VectorInt2(6, 1));
            report.WriteLine(path);

            Assert.That(report, Is.EqualTo(new TestReport(
            @".............
            ......XXXX...
            .........X...
            .............
            .........X...
            .............

            DDDLUURULLL
            ")));
        }
Пример #8
0
        private static List<StaticMaps.LineBitmap> FindWalls(StaticMaps staticMaps)
        {
            var cornerAndSide = staticMaps.CornerMap.BitwiseOR(staticMaps.SideMap);
            var res = new List<StaticMaps.LineBitmap>();
            res.AddRange(FindRunsHorx(cornerAndSide));
            res.AddRange(FindRunsVert(cornerAndSide));

            return res;
        }
Пример #9
0
        private static IBitmap FindSides(StaticMaps staticMaps)
        {
            var res = new Bitmap(staticMaps.FloorMap.Size);
            foreach (var floor in staticMaps.FloorMap.TruePositions())
            {
                if (staticMaps.CornerMap[floor]) continue;  // Corners cannot be doors

                // ###
                // ?.?
                if (staticMaps.WallMap[floor + VectorInt2.Up]
                    && staticMaps.WallMap[floor + VectorInt2.Up + VectorInt2.Left]
                    && staticMaps.WallMap[floor + VectorInt2.Up + VectorInt2.Right]) res[floor] = true;

                // ?.?
                // ###
                if (staticMaps.WallMap[floor + VectorInt2.Down]
                    && staticMaps.WallMap[floor + VectorInt2.Down + VectorInt2.Left]
                    && staticMaps.WallMap[floor + VectorInt2.Down + VectorInt2.Right]) res[floor] = true;

                // #?
                // #.
                // #?
                if (staticMaps.WallMap[floor + VectorInt2.Left]
                    && staticMaps.WallMap[floor + VectorInt2.Left + VectorInt2.Up]
                    && staticMaps.WallMap[floor + VectorInt2.Left + VectorInt2.Down]) res[floor] = true;

                // ?#
                // .#
                // ?#
                if (staticMaps.WallMap[floor + VectorInt2.Right]
                    && staticMaps.WallMap[floor + VectorInt2.Right + VectorInt2.Up]
                    && staticMaps.WallMap[floor + VectorInt2.Right + VectorInt2.Down]) res[floor] = true;

            }
            return res;
        }
Пример #10
0
 private static List<StaticMaps.LineBitmap> FindRecesses(StaticMaps staticMaps)
 {
     return
         staticMaps.IndividualWalls.Where(x => staticMaps.CornerMap[x.Start] && staticMaps.CornerMap[x.End])
             .ToList();
 }
Пример #11
0
        public static StaticMaps Generate(Puzzle puzzle)
        {
            var s= new StaticMaps()
            {
                WallMap = puzzle.ToMap(puzzle.Definition.Wall, puzzle.Definition.Void),
                FloorMap = puzzle.ToMap(puzzle.Definition.AllFloors),
                GoalMap = puzzle.ToMap(puzzle.Definition.AllGoals),
                CrateStart = puzzle.ToMap(puzzle.Definition.AllCrates),
            };

            // Complex
            s.CornerMap = FindCorners(s);
            s.DoorMap = FindDoors(s);
            s.SideMap = FindSides(s);

            s.IndividualWalls = FindWalls(s);
            s.RecessMap = FindRecesses(s);
            return s;
        }
Пример #12
0
        public static IBitmap FindCorners(StaticMaps staticMaps)
        {
            var res = new Bitmap(staticMaps.FloorMap.Size);
            foreach (var floor in staticMaps.FloorMap.TruePositions())
            {
                // ##
                // #.
                if (staticMaps.WallMap[floor + VectorInt2.Up] &&
                    staticMaps.WallMap[floor + VectorInt2.Left]

                    )
                {
                    res[floor] = true;
                }

                // ##
                // .#
                if (staticMaps.WallMap[floor + VectorInt2.Up] &&
                    staticMaps.WallMap[floor + VectorInt2.Right]
                    )
                {
                    res[floor] = true;
                }

                // .#
                // ##
                if (staticMaps.WallMap[floor + VectorInt2.Down] &&
                    staticMaps.WallMap[floor + VectorInt2.Right]
                    )
                {
                    res[floor] = true;
                }

                // #.
                // ##
                if (staticMaps.WallMap[floor + VectorInt2.Down] &&
                    staticMaps.WallMap[floor + VectorInt2.Left]
                    )
                {
                    res[floor] = true;
                }
            }
            return res;
        }