Esempio n. 1
0
        private bool CanMoveBox(Key from, Key to, int initialKeeperPos, int boxPosition, out Position newBoxPosition)
        {
            var toSide = map.GetPosition(to, boxPosition);

            newBoxPosition = map.Convert(toSide);
            int tmp;

            if (!map.CanMoveBox(to, boxPosition, out tmp))
            {
                return(false);
            }

            var fromSide = map.GetPosition(from, boxPosition);

            if (fromSide != map.Convert(startNode.Cell))
            {
                if (map[fromSide] != SokobanMap.EMPTY &&
                    map[fromSide] != SokobanMap.LOCATION &&
                    map[fromSide] != SokobanMap.KEEPER &&
                    map[fromSide] != SokobanMap.KEEPER_ON_LOCATION)
                {
                    return(false);
                }

                var keeperPathFinder = new KeeperPathFinder(map);
                var pathToBoxSide    = keeperPathFinder.FindPath(map.Convert(initialKeeperPos), map.Convert(fromSide));

                return(pathToBoxSide.Length > 0);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 2
0
        protected override IEnumerable <Position> GetAdjacentCells(Position cell, int depth)
        {
            var neighbors = new List <Position>();

            foreach (var key in SokobanMap.SupportedKeys)
            {
                var targetPos = map.GetPosition(key, cell);
                var pos       = new Position(targetPos, map.Width, map.Height);

                if (IsWalkable(pos))
                {
                    neighbors.Add(pos);
                }
            }

            return(neighbors);
        }