コード例 #1
0
        public KakuBoxMovingStep(KakuBoxState state, int movingBoxIndex, BoxMovingDirection boxMovingDirection)
            : base(state, movingBoxIndex, boxMovingDirection)
        {
            var movingBox = state[movingBoxIndex];

            switch (boxMovingDirection)
            {
            case BoxMovingDirection.Up:
                kakuPushingPoint = new Point(movingBox.X, movingBox.Y - 1);
                break;

            case BoxMovingDirection.Down:
                kakuPushingPoint = new Point(movingBox.X, movingBox.Y + 1);
                break;

            case BoxMovingDirection.Left:
                kakuPushingPoint = new Point(movingBox.X + 1, movingBox.Y);
                break;

            case BoxMovingDirection.Right:
                kakuPushingPoint = new Point(movingBox.X - 1, movingBox.Y);
                break;

            default: break;
            }
        }
コード例 #2
0
        public bool Check(BoxMovingStep movingStep)
        {
            KakuBoxState state = (KakuBoxState)movingStep.Final;

            var finds = queue.FindSameBoxState(state);

            if (finds.Count > 0)
            {
                foreach (var find in finds)
                {
                    if (find.Kaku.Equals(state.Kaku))
                    {
                        return(false);
                    }
                    else
                    {
                        var newMap = new ExtendedMap(this.map, find.Boxs);

                        PointToPointPathFinder pathFinder = new PointToPointPathFinder(newMap, find.Kaku);

                        if (pathFinder.HasPath(state.Kaku))
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
コード例 #3
0
        public override bool Equals(Object obj)
        {
            KakuBoxState s = obj as KakuBoxState;

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

            return(kaku == s.kaku && base.Equals(obj));
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: icyjiang/KakuBoxMoving
        static void Main(string[] args)
        {
            Map map = new Map(new Point[] { new Point(0, 0), new Point(0, 1), new Point(3, 0), new Point(4, 0), new Point(5, 0), new Point(1, 3)
                                            , new Point(3, 2), new Point(3, 4) });

            map.XDownBound = 0;
            map.XUpBound   = 5;
            map.YDownBound = 0;
            map.YUpBound   = 4;

            KakuBoxState start = new KakuBoxState(new Point(5, 4), new Point[] { new Point(1, 2), new Point(3, 3), new Point(4, 2) });
            BoxState     end   = new BoxState(new Point[] { new Point(2, 1), new Point(2, 2), new Point(2, 4) });

            KakuBoxMovingFinder finder = new KakuBoxMovingFinder(map, start);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            var path = finder.FindPath(end);

            sw.Stop();

            if (path.Count > 0)
            {
                Console.WriteLine("Find it!");

                foreach (var state in path)
                {
                    Console.WriteLine(state.ToString());
                }
            }
            else
            {
                Console.WriteLine("No answer. Are you kidding me!");
            }
            Console.WriteLine("Total used time:{0}", sw.Elapsed.TotalSeconds);
            Console.ReadLine();
        }