MazeFrameData CreateSampleMazeFrameData() { var data = new MazeFrameData(); data.SizeX = data.SizeY = 6; foreach (var wallPosition in new[] {
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); }
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); }
public MazeFrameViewModel(MazeFrameData mazeFrameData, MazeContentData mazeContentData) { this.MazeFrameData = mazeFrameData; this.MazeContentData = mazeContentData; }