public Random_Kurskal(int _n, int _m) { n = _n; m = _m; output = new MazeStruct(n, m); id = new int[n, m]; dj = new int[n * m]; vec = new List <node>(); }
private void KurskalBtn_Click(object sender, EventArgs e) { if (runner.IsAlive) { return; } Random_Kurskal rk = new Random_Kurskal(n, m); myMaze = rk.Generate(); clearPb(); }
private void abBtn_Click(object sender, EventArgs e) { if (runner.IsAlive) { return; } Aldous_Broder ab = new Aldous_Broder(n, m); myMaze = ab.Generate(); clearPb(); }
public Aldous_Broder(int _n, int _m) { n = _n; m = _m; dir = new int[4, 2]; dir[0, 0] = 1; dir[0, 1] = 0; dir[1, 0] = 0; dir[1, 1] = 1; dir[2, 0] = -1; dir[2, 1] = 0; dir[3, 0] = 0; dir[3, 1] = -1; vis = new bool[n, m]; vec = new List <int>(); output = new MazeStruct(n, m); id = new int[n, m]; dj = new int[n * m]; Vec = new List <Node>(); }
public MainData(int _n, int _m, float _pW, float _pH, float _stx, float _sty, float _edx, float _edy, MazeStruct _myMaze, Queue _Que, int _delay) { n = _n; m = _m; pW = _pW; pH = _pH; stx = _stx; sty = _sty; edx = _edx; edy = _edy; myMaze = _myMaze; Que = _Que; delay = _delay; }
public void GenerateTest1() { // Arrange IMazeGenerator mazeGenerator = new ReqursiveGenerator(null); int mazeSize = 5; // Act MazeStruct mazeStruct = mazeGenerator.GenerateMazeStruct(mazeSize); //using (System.IO.StreamWriter stream = new System.IO.StreamWriter(Guid.NewGuid().ToString())) //{ // stream.Write(Serializer<MazeStruct>.ToXml(mazeStruct)); //} // Asserts Assert.AreEqual(mazeSize, mazeStruct.Size); }
public void MazeFixer(MazeStruct ms) { vec.Clear(); int cnt = 0; for (int i = 1; i < n; i += 2) { for (int j = 1; j < m; j += 2) { id[i, j] = ++cnt; } } for (int i = 1; i < n - 1; i++) { for (int j = 1; j < m - 1; j++) { if (ms.maze[i, j] == 1) { if ((ms.maze[i, j - 1] == 0) && (ms.maze[i, j + 1] == 0)) { vec.Add(new node(id[i, j - 1], id[i, j + 1], i, j)); } else if ((ms.maze[i - 1, j] == 0) && (ms.maze[i + 1, j] == 0)) { vec.Add(new node(id[i - 1, j], id[i + 1, j], i, j)); } } } } for (int i = 1; i <= cnt; i++) { dj[i] = i; } List <node> randvec = vec.OrderBy(a => Guid.NewGuid()).ToList <node>(); for (int i = 0; i < randvec.Count; i++) { if (find(randvec[i].a) != find(randvec[i].b)) { ms.maze[randvec[i].x, randvec[i].y] = 0; dj[find(randvec[i].a)] = find(randvec[i].b); } } }
public void NewtosoftSer() { MazeStruct str = new MazeStruct(new MazeGeneral.Maze.MazeGenerators.ReqursiveGenerator(null).GenerateMazeCells(10)); CompressXmlSerializer xml = new CompressXmlSerializer(); NewtosoftJsonSerialzer newtosoftJson = new NewtosoftJsonSerialzer(); CompressNewtosoftSerializer compressNewtosoftSerializer = new CompressNewtosoftSerializer(); string strXml = xml.ToStringFormat <MazeStruct>(str); string strJSON = newtosoftJson.ToStringFormat <MazeStruct>(str); string strCompressJSON = compressNewtosoftSerializer.ToStringFormat <MazeStruct>(str); if (strJSON.Length < strXml.Length) { Assert.Fail(); } if (strCompressJSON.Length < strXml.Length) { Assert.Fail(); } }
public MazeForm(int _n, int _m, string path = "", bool old = false) { InitializeComponent(); _o = true; DesktopLocation = new Point(100, 100); n = _n; m = _m; if (path != "") { using (StreamReader file = new StreamReader(path)) { n = Convert.ToInt32(file.ReadLine()); m = Convert.ToInt32(file.ReadLine()); sty = Convert.ToInt32(file.ReadLine()); stx = Convert.ToInt32(file.ReadLine()); edy = Convert.ToInt32(file.ReadLine()); edx = Convert.ToInt32(file.ReadLine()); myMaze = new MazeStruct(n, m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { myMaze.maze[i, j] = file.Read() - '0'; } } } } else { int tmp = n; n = m; m = tmp; myMaze = new MazeStruct(n, m); stx = sty = 1; edx = n - 2; edy = m - 2; } string subPath = "Mazes"; this.openFileDialog1.InitialDirectory = Path.Combine(Application.StartupPath, subPath); this.saveFileDialog1.InitialDirectory = Path.Combine(Application.StartupPath, subPath); bool exists = System.IO.Directory.Exists(Path.Combine(Application.StartupPath, subPath)); if (!exists) { System.IO.Directory.CreateDirectory(Path.Combine(Application.StartupPath, subPath)); } LB.DisplayMember = "name"; LB.ValueMember = "value"; Queue myQue = new Queue(); Que = Queue.Synchronized(myQue); DoubleBuffered = true; panelMaze.Height = 610; panelMaze.Width = 610; pH = panelMaze.Height / m; pW = panelMaze.Width / n; bmp = new Bitmap((int)pH * m, (int)pW * n); mainPb = new PictureBox(); mainPb.MouseClick += panelMaze_MouseClick; mainPb.MouseMove += panelMaze_MouseMove; mainPb.MouseLeave += panelMaze_MouseLeave_1; mainPb.Height = (int)pH * m; mainPb.Width = (int)pW * n; mainPb.Location = new Point(0, 0); mainPb.Image = bmp; panelMaze.Height = (int)pH * m; panelMaze.Width = (int)pW * n; panelMaze.Controls.Add(mainPb); runner = new Thread(initMaze); st_Lb.Text = "(" + stx.ToString() + "," + sty.ToString() + ")"; ed_Lb.Text = "(" + edx.ToString() + "," + edy.ToString() + ")"; radioButton1.Checked = true; md = new MainData(n, m, pW, pH, stx, sty, edx, edy, myMaze, Que, 0); timer.Enabled = true; initMaze(); clearPb(); now = new Stopwatch(); this.FormClosing += new FormClosingEventHandler(Maze_FormClosing); }