Пример #1
0
        public List <T> FindSameBoxState(BoxState state)
        {
            if (state == null)
            {
                return(new List <T>());
            }

            return(list.FindAll(s => s.IsBoxStateEquals(state)));
        }
Пример #2
0
        public override bool Equals(Object obj)
        {
            BoxState s = obj as BoxState;

            if (object.ReferenceEquals(s, null))
            {
                return(false);
            }

            return(this.IsBoxStateEquals(s));
        }
Пример #3
0
        public bool HasPath(BoxState end)
        {
            if (!ValidEnd(end))
            {
                return(false);
            }

            if (this.queue.FindSameBoxState(end).Count > 0)
            {
                return(true);
            }

            return(RunToStop(state => state.IsBoxStateEquals(end)));
        }
Пример #4
0
        public BoxMovingStep(BoxState state, int movingBoxIndex, BoxMovingDirection boxMovingDirection)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            if (movingBoxIndex < 0 || movingBoxIndex >= state.BoxCount)
            {
                throw new ArgumentOutOfRangeException("movingBoxIndex");
            }

            Orignal         = state;
            MovingBoxIndex  = movingBoxIndex;
            MovingDirection = boxMovingDirection;
        }
Пример #5
0
        public bool IsBoxStateEquals(BoxState state)
        {
            if (state == null || state.boxs.Length != this.boxs.Length)
            {
                return(false);
            }

            var s = boxs.ToList();
            var d = state.boxs.ToList();

            for (int i = 0; i < boxs.Length; i++)
            {
                if (!d.Remove(s[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #6
0
        public List <BoxState> FindPath(BoxState end)
        {
            List <BoxState> path = new List <BoxState>();

            if (this.HasPath(end))
            {
                BoxState find = this.queue.FindSameBoxState(end).First();

                path.Add(find);

                while (find.Parent != null)
                {
                    path.Add(find.Parent);
                    find = find.Parent;
                }

                path.Reverse();
            }
            return(path);
        }
Пример #7
0
 private bool ValidEnd(BoxState end)
 {
     if (end == null)
     {
         throw new ArgumentNullException("end");
     }
     if (end.IsOverlapping)
     {
         return(false);
     }
     if (start.BoxCount != end.BoxCount)
     {
         return(false);
     }
     if (!end.IsMeetMap(map))
     {
         return(false);
     }
     return(true);
 }