当前位置: 首页>>代码示例>>C#>>正文


C# Puzzle.ToMap方法代码示例

本文整理汇总了C#中Puzzle.ToMap方法的典型用法代码示例。如果您正苦于以下问题:C# Puzzle.ToMap方法的具体用法?C# Puzzle.ToMap怎么用?C# Puzzle.ToMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Puzzle的用法示例。


在下文中一共展示了Puzzle.ToMap方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

 public static StateMaps Create(Puzzle puzzle)
 {
     return new StateMaps()
     {
         CrateMap = puzzle.ToMap(puzzle.Definition.AllCrates),
         MoveMap = FloodFill.Fill(puzzle.ToMap(puzzle.Definition.Wall), puzzle.Player.Position)
     };
 }
开发者ID:guylangston,项目名称:SokoSolve,代码行数:8,代码来源:StateMaps.cs

示例2: FindPath

        public void FindPath()
        {
            var textPuzzle = new Puzzle(new string[]
            {
                "~~~###~~~~~",
                "~~## #~####",
                "~##e ###  #",
                "## X      #",
                "#    X #  #",
                "### X###  #",
                "~~#  #    #",
                "~## ## # ##",
                "~#   s  ##~",
                "~#     ##~~",
                "~#######~~~",
            });

            var boundry = textPuzzle.ToMap('#', 'X');

            var start = textPuzzle.Where(x=>x=='s').First().Position;
            var end = textPuzzle.Where(x=>x=='e').First().Position;

            var result = PathFinder.Find(boundry, start, end);

            Assert.That(result, Is.Not.Null);

            Assert.That(result.ToString(), Is.EqualTo("LLUUUURUUL"));
        }
开发者ID:guylangston,项目名称:SokoSolve,代码行数:28,代码来源:PathFinderTests.cs

示例3: CaseA

        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..........
            .............
            ............."
                )));
        }
开发者ID:guylangston,项目名称:SokoSolve,代码行数:40,代码来源:PushMapTests.cs

示例4: Evalute

 public PuzzleState Evalute(Puzzle current)
 {
     var crateMap = current.ToMap(current.Definition.AllCrates);
     return new PuzzleState()
     {
         Static = Static,
         Current = new StateMaps()
         {
             CrateMap = crateMap,
             MoveMap = FloodFill.Fill(Static.WallMap.BitwiseOR(crateMap), current.Player.Position)
         }
     };
 }
开发者ID:guylangston,项目名称:SokoSolve,代码行数:13,代码来源:PuzzleAnalysis.cs

示例5: OverAndBackAgain

        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);
        }
开发者ID:guylangston,项目名称:SokoSolve,代码行数:54,代码来源:PushMapTests.cs

示例6: MultipleCrates

        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..
            .............
            "
                )));
        }
开发者ID:guylangston,项目名称:SokoSolve,代码行数:41,代码来源:PushMapTests.cs

示例7: CaseB_WithPath

        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
            ")));
        }
开发者ID:guylangston,项目名称:SokoSolve,代码行数:43,代码来源:PushMapTests.cs

示例8: Init

        public SolverNode Init(Puzzle puzzle, ISolverQueue queue)
        {
            var solution = puzzle.ToMap(puzzle.Definition.AllGoals);  // START with a solution
            var walls = puzzle.ToMap(puzzle.Definition.Wall);
            // The is only one start, but MANY end soutions. Hence a single root is not a valid representation
            // We use a placeholder node (not an actualy move to hold solutions)
            var root = new SingleThreadedReverseSolver.SyntheticReverseNode()
            {
                CrateMap = puzzle.ToMap(puzzle.Definition.AllGoals),
                MoveMap = new Bitmap(puzzle.Width, puzzle.Height)
            };

            foreach (var crateBefore in solution.TruePositions())
            {
                foreach (var dir in VectorInt2.Directions)
                {
                    // ss
                    var posPlayer = crateBefore + dir;
                    var posPlayerAfter = posPlayer + dir;
                    var crateAfter = crateBefore + dir;

                    // Remember: In reverse mode goals are crates, and crate may be floor
                    if ((puzzle[posPlayer] == puzzle.Definition.Floor
                        || puzzle[posPlayer] == puzzle.Definition.Player
                        || puzzle[posPlayer] == puzzle.Definition.Crate
                        )
                        &&
                        (puzzle[posPlayerAfter] == puzzle.Definition.Floor
                        || puzzle[posPlayerAfter] == puzzle.Definition.Player
                        || puzzle[posPlayer] == puzzle.Definition.Crate
                        )
                        )
                    {

                            var crate = new Bitmap(solution);
                            crate[crateBefore] = false;
                            crate[crateAfter] = true;

                            var node = new SolverNode()
                            {
                                CrateBefore = crateBefore,
                                CrateAfter = crateAfter,

                                PlayerBefore = posPlayer,
                                PlayerAfter = posPlayerAfter,

                                CrateMap = crate,
                                MoveMap = FloodFill.Fill(walls.BitwiseOR(crate), posPlayerAfter)
                            };

                            if (node.MoveMap.Count > 0)
                            {
                                root.Add(node);
                                queue.Enqueue(node);
                            }

                    }
                }
            }
            return root;
        }
开发者ID:guylangston,项目名称:SokoSolve,代码行数:61,代码来源:ReverseEvaluator.cs

示例9: Normalise

        public static Puzzle Normalise(Puzzle puzzle)
        {
            var allFloor = puzzle.ToMap(puzzle.Definition.AllFloors);
            var trueFloor = FloodFill.Fill(allFloor.Invert(), puzzle.Player.Position);
            var wall = trueFloor.Invert();

            var norm = new Puzzle(puzzle);
            foreach (var w in wall.TruePositions())
            {
                norm[w] = puzzle.Definition.Wall;
            }

            return norm;
        }
开发者ID:guylangston,项目名称:SokoSolve,代码行数:14,代码来源:StaticAnalysis.cs

示例10: Generate

        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;
        }
开发者ID:guylangston,项目名称:SokoSolve,代码行数:19,代码来源:StaticAnalysis.cs


注:本文中的Puzzle.ToMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。