Example #1
0
        public PuzzleState Evalute(Puzzle current)
        {
            var crateMap = current.ToMap(current.Definition.AllCrates);

            return(new PuzzleState(Static,
                                   new StateMaps(crateMap,
                                                 SolverHelper.FloodFillUsingWallAndCrates(Static.WallMap, crateMap, current.Player.Position))
                                   ));
        }
Example #2
0
            public void Evalulate(Node node, IStragetgyItterator <Node> itterator)
            {
                var free = Static.FloorMap.Subtract(node.Maps.CrateMap);

                foreach (var move in node.Maps.MoveMap.TruePositions())
                {
                    var dir = node.CrateTarget - move;
                    if (dir == VectorInt2.Up || dir == VectorInt2.Down || dir == VectorInt2.Left ||
                        dir == VectorInt2.Right) // Next to each other
                    {
                        var p   = move;
                        var pp  = node.CrateTarget;
                        var ppp = node.CrateTarget + dir;

                        if (free.Contains(ppp) && free[ppp])
                        {
                            var newCrate = new Bitmap(node.Maps.CrateMap);
                            newCrate[pp]  = false;
                            newCrate[ppp] = true;

                            var newMove = SolverHelper.FloodFillUsingWallAndCrates(Static.WallMap, newCrate, pp);

                            var newNode = new Node
                            {
                                PlayerBefore = p,
                                PlayerAfter  = pp,
                                CrateTarget  = ppp,

                                Maps = new StateMaps(newCrate, newMove)
                            };

                            // Does this already exist
                            if (!CrateMap[ppp])
                            {
                                // New crate position
                                node.Add(newNode);
                                itterator.Add(newNode);
                                CrateMap[ppp] = true;
                            }
                            else
                            {
                                // the crate may exist, but we have a new move map
                                var match = node.Root().FirstOrDefault(x => x.Maps.Equals(newNode.Maps));
                                if (match == null)
                                {
                                    node.Add(newNode);
                                    itterator.Add(newNode);
                                }
                            }
                        }
                    }
                }
            }