Example #1
0
        static public bool IsInDeadLock(this iBoard b)
        {
            string boardInfo = b.GetBoardInfo(true);

            if (b.Steps.Any(us => us._boardInfo == boardInfo))
            {
                return(true);
            }
            for (int y = 1; y < b.Height - 1; y++)
            {
                for (int x = 1; x < b.Width - 1; x++)
                {
                    if (IsBoxNotInPlace(b[x, y]))
                    {
                        bool u = b.CanNotBeMoved(x, y, MoveType.Up);
                        bool d = b.CanNotBeMoved(x, y, MoveType.Down);
                        bool l = b.CanNotBeMoved(x, y, MoveType.Left);
                        bool r = b.CanNotBeMoved(x, y, MoveType.Right);
                        if ((u || d) && (l || r))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Example #2
0
        static bool CanNotBeMoved(this iBoard b, int x, int y, MoveType mt)
        {
            mt.Move(ref x, ref y);
            CellType t = b[x, y];

            if (t == CellType.Wall)
            {
                return(true);
            }

            if (Is(t, CellType.Box))
            {
                bool u = mt == MoveType.Down || b.CanNotBeMoved(x, y, MoveType.Up);
                bool d = mt == MoveType.Up || b.CanNotBeMoved(x, y, MoveType.Down);
                bool l = mt == MoveType.Right || b.CanNotBeMoved(x, y, MoveType.Left);
                bool r = mt == MoveType.Left || b.CanNotBeMoved(x, y, MoveType.Right);
                if ((u || d) && (l || r))
                {
                    return(true);
                }
            }

            return(false);
        }