예제 #1
0
        public int [,] MakeMazeMap(MazeFrameData frameData, MazeContentData contentData)
        {
            // 箱座標系と壁座標系を1つの座標系にマップ
            // ・─・─・─・─・
            // | | | | |
            // ・─・─・─・─・
            // | | | | |
            // ・─・─・─・─・
            // | | | | |
            // ・─・─・─・─・
            // | | | | |
            // ・─・─・─・─・

            var map = new int[frameData.SizeX * 2 + 1, frameData.SizeY * 2 + 1];

            // 壁埋め
            foreach (var wallPosition in frameData.WallPositions)
            {
                // 座標変換
                var x  = 0;
                var y  = 0;
                var p1 = wallPosition.Item1;
                var p2 = wallPosition.Item2;
                if (p1.x1 == p2.x2)
                {
                    // 縦壁
                    x         = p1.x1 * 2;
                    y         = p1.y1 * 2 + 1;
                    map[x, y] = MazeMapLegend.VerticalWall;
                }
                else
                {
                    // 横壁
                    x         = p1.x1 * 2 + 1;
                    y         = p1.y1 * 2;
                    map[x, y] = MazeMapLegend.HorizontalWall;
                }
            }

            // 箱埋め
            map[contentData.RedboxPosition.Value.x * 2 + 1, contentData.RedboxPosition.Value.y * 2 + 1]       = MazeMapLegend.Redbox;
            map[contentData.YellowboxPosition.Value.x * 2 + 1, contentData.YellowboxPosition.Value.y * 2 + 1] = MazeMapLegend.Yellowbox;
            foreach (var greenbox in contentData.GreenboxPositions)
            {
                map[greenbox.x * 2 + 1, greenbox.y * 2 + 1] = MazeMapLegend.Greenbox;
            }

            // ゴール埋め
            map[frameData.GoalPosition.Value.x * 2 + 1, frameData.GoalPosition.Value.y * 2 + 1] = MazeMapLegend.Goal;

            return(map);
        }
예제 #2
0
        public int Compute(MazeFrameData frame, MazeContentData content)
        {
            this.Frame = frame;

            Broadcast(ComputationMessageHeader.Message, "Begin Compute()");

            var map = makeMazeMapLogic.MakeMazeMap(frame, content);

            // 局面の圧縮 (箱の位置だけ)
            // R(x,y)Y(x,y)G(x1,y1)(x2,y2)...
            var compressedInitial = compressMapLogic.Compress(map);

            var             counts = 0;
            MazeMapPosition reachedGoalMapPosition;

            var q = new Queue <MazeMapPosition>();

            q.Enqueue(new MazeMapPosition {
                Parent = null, Position = compressedInitial
            });

            while (q.Count > 0)
            {
                // 処理のキャンセル通知のポーリング
                if ((counts++ % CheckCancelInterval) == 0)
                {
                    if (cancels)
                    {
                        Broadcast(ComputationMessageHeader.Message, "Cancel Compute()");
                        return(1);
                    }
                }

                Expand(q, out reachedGoalMapPosition, counts);
                if (reachedGoalMapPosition != null)
                {
                    // ルートの逆探索
                    var mapPositionLinks = MazeMapHistory.GetMapPositionLinks(reachedGoalMapPosition.Position, true);
                    Broadcast(ComputationMessageHeader.Message, "ゴールに至るルートを発見");
                    Broadcast(ComputationMessageHeader.RouteToGoal, mapPositionLinks);
                    break;
                }
            }

            Broadcast(ComputationMessageHeader.Message, "End Compute()");

            return(0);
        }
예제 #3
0
        public MazeContentData Expand(ulong[] compressed)
        {
            // 赤箱 → 黄箱 → 緑箱1 → 緑箱2 → ...

            var positions = ConvertToPositions(compressed);

            var content = new MazeContentData();

            if (positions.Count > 0)
            {
                content.RedboxPosition = positions[0];
            }
            if (positions.Count > 1)
            {
                content.YellowboxPosition = positions[1];
            }
            for (var i = 2; i < positions.Count; ++i)
            {
                content.AddGreenbox(positions[i]);
            }

            return(content);
        }
 public MazeFrameViewModel(MazeFrameData mazeFrameData, MazeContentData mazeContentData)
 {
     this.MazeFrameData   = mazeFrameData;
     this.MazeContentData = mazeContentData;
 }
 public RedboxTreeViewItemSelectedEventArgs(MazeContentData content) => this.Content = content;
예제 #6
0
 public void RaiseSelectedItemChangedEvent(MazeContentData selectedItem) =>
 RedboxTreeViewItemSelected?.Invoke(this, new RedboxTreeViewItemSelectedEventArgs(selectedItem));