あにす #5366(2008/01/16 12:01 GMT) [ C# ] Rating0/0=0.00
まだC#のコードがない様なので、遅すぎて恥ずかしいのを我慢して投稿します。
OS:Windows XP Home SP2 CPU:AMD Sempron 3400+ 1.99GHz メモリ:480MB
ファイルへの出力で15分から1時間位の間で変動するようです。
掘った方向をメモして枝切りすればもう少し速くなるかも。
see: 迷路自動生成アルゴリズム
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
//http://ja.doukaku.org/123/ 投稿用 using System; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { long tick = DateTime.Now.Ticks; const int X = 0; const int Y = 1; int xSize = int.Parse(args[0]); int ySize = int.Parse(args[1]); Random rnd = new Random(); //注目点初期化 int x = rnd.Next(0, xSize - 1) * 2 + 1; int y = rnd.Next(0, ySize - 1) * 2 + 1; List<int[]> canDigRoard = new List<int[]>();//注目点とすることが出来るセル bool[,] maze = new bool[xSize * 2 + 1, ySize * 2 + 1];//迷路データ trueが道、falseが壁 //全部壁にする for(int i = 0; i < maze.GetLength(X); i++) { for(int j = 0; j < maze.GetLength(Y); j++) { maze[i, j] = false; } } maze[x,y] = true; canDigRoard.Add(new int[] { x, y }); //メインループ while(true) { int[][] directionList = new int[][] { new int[] { -1, 0 }, new int[] { 1, 0 }, new int[] { 0, -1 }, new int[] { 0, 1 } }; int directionListLast = directionList.Length - 1; int[] direction;//方向 do { int directionListIndex = rnd.Next(directionListLast); direction = directionList[directionListIndex]; directionList[directionListIndex] = directionList[directionListLast--]; if(maze.GetLength(X) > x + direction[X] * 2 && maze.GetLength(Y) > y + direction[Y] * 2 && x + direction[X] * 2 >= 0 && y + direction[Y] * 2 >= 0) {//インデックスが範囲内か判定 if(!(maze[x + direction[X] * 2, y + direction[Y] * 2])) {//2マス先が道かどうか maze[x + direction[X], y + direction[Y]] = true; maze[x + direction[X] * 2, y + direction[Y] * 2] = true; canDigRoard.Add(new int[] { x + direction[X] * 2, y + direction[Y] * 2 }); break; } } } while(directionListLast != -1); if(directionListLast == -1){ for(int i = 0; i < canDigRoard.Count; i++) { if(canDigRoard[i][X] == x && canDigRoard[i][Y] == y) { canDigRoard.RemoveAt(i); } } if(canDigRoard.Count == 0) break; int canDigRoardIndex = rnd.Next(0, canDigRoard.Count - 1); x = canDigRoard[canDigRoardIndex][X]; y = canDigRoard[canDigRoardIndex][Y]; } else { x += direction[X] * 2; y += direction[Y] * 2; } } string time = (DateTime.Now.Ticks - tick) / 10000L + "ms"; //出力 StringBuilder sb = new StringBuilder(); for(int i = 0; i < maze.GetLength(Y); i++) { for(int j = 0; j < maze.GetLength(X); j++) { sb.Append(maze[j, i] ? " " : "■"); } sb.AppendLine(); } Console.WriteLine(sb + time); Console.ReadLine(); } }
Rating0/0=0.00-0+
[ reply ]
あにす
#5366()
[
C#
]
Rating0/0=0.00
まだC#のコードがない様なので、遅すぎて恥ずかしいのを我慢して投稿します。
OS:Windows XP Home SP2 CPU:AMD Sempron 3400+ 1.99GHz メモリ:480MB
ファイルへの出力で15分から1時間位の間で変動するようです。
掘った方向をメモして枝切りすればもう少し速くなるかも。
see: 迷路自動生成アルゴリズム
Rating0/0=0.00-0+
[ reply ]