public static bool[,] mitNiveau(int niveau, out int d, out int x, out int y) { switch (niveau) { case 1: return(Tafel.GenerateMaze(0, 0, false, 0, out d, out x, out y)); case 2: var ar = Tafel.GenerateManyCrosses(); d = Tafel.PrüfRichtung(ar, out x, out y); return(ar); case 3: return(GenerateWithDensity(1, 0.1f, out d, out x, out y, false)); case 4: return(Tafel.GenerateWithDensity(1, 0.5f, out d, out x, out y, false)); case 5: return(Tafel.GenerateWithDensity(1, 0.5f, out d, out x, out y, false)); case 6: return(Tafel.GenerateWithDensity(1, 0.5f, out d, out x, out y, true)); case 7: return(Tafel.GenerateWithDensity(1, 0.9f, out d, out x, out y, true)); case 8: return(Tafel.GenerateWithDensity(2, 0.1f, out d, out x, out y, false)); case 9: return(Tafel.GenerateWithDensity(2, 0.9f, out d, out x, out y, false)); case 10: return(Tafel.GenerateWithDensity(2, 0.5f, out d, out x, out y, false)); case 11: return(Tafel.GenerateWithDensity(3, 0.1f, out d, out x, out y, false)); case 12: return(Tafel.GenerateWithDensity(3, 0.9f, out d, out x, out y, false)); case 13: return(Tafel.GenerateWithDensity(3, 0.5f, out d, out x, out y, false)); case 14: return(Tafel.GenerateWithDensity(3, 0.5f, out d, out x, out y, false)); case 15: return(Tafel.GenerateWithDensity(3, 0.5f, out d, out x, out y, false)); default: x = 0; y = 0; d = -2; return(null); } }
public static bool[,] GenerateWithDensity(int generate, float density, out int pr, out int x, out int y, bool verbesser) { int i = 0; while (true) { i++; if (i > 1000000) { break; } bool[,] ar = Tafel.Random(rand.Next(0, 1000000), density); pr = generate == 1 ? Tafel.PrüfRichtung(ar, out x, out y) : (generate == 2 ? Tafel.PrüfRichtungMitHinzufügen(ar, out x, out y) : Tafel.PrüfRichtungMitHinzuhinzufügen(ar, out x, out y)); if (pr == 1 || pr == -1) { if (verbesser) { int c = 0; while (Verbesser(ar, generate, ref x, ref y) && c < 100) { c++; } } return(ar); } } x = 0; y = 0; pr = -2; return(null); }
public static bool Verbesser(bool[,] ar, int generate, ref int x, ref int y) { var replacementsmade = false; x = 0; y = 0; int ax = 0; int ay = 0; var orig_pr = Tafel.PrüfRichtung(ar, out x, out y); for (var i = 1; i < Tafel.TW - 5; i++) { for (var j = 1; j < Tafel.TH - 1; j++) { var v0 = ar[i + 0, j]; var v1 = ar[i + 1, j]; var v2 = ar[i + 2, j]; var v3 = ar[i + 3, j]; if ((v0 == !v1) && (v0 == !v2) && (v0 == v3)) { var r = rand.Next(0, 4); ar[i + r, j] = !ar[i + r, j]; var new_pr = (generate == 2) ? Tafel.PrüfRichtungMitHinzufügen(ar, out ax, out ay) : ( (generate == 1) ? Tafel.PrüfRichtung(ar, out ax, out ay) //else muss 3 sein : Tafel.PrüfRichtungMitHinzuhinzufügen(ar, out ax, out ay) ); if (new_pr != orig_pr) { ar[i + r, j] = !ar[i + r, j]; } else { x = ax; y = ay; replacementsmade = true; } } } } for (var i = 1; i < Tafel.TW - 1; i++) { for (var j = 1; j < Tafel.TH - 4; j++) { var v0 = ar[i, j]; var v1 = ar[i, j + 1]; var v2 = ar[i, j + 2]; var v3 = ar[i, j + 3]; if ((v0 == !v1) && (v0 == !v2) && (v0 == v3)) { var r = rand.Next(0, 4); ar[i, j + r] = !ar[i, j + r]; var new_pr = (generate == 2) ? Tafel.PrüfRichtungMitHinzufügen(ar, out ax, out ay) : ( (generate == 1) ? Tafel.PrüfRichtung(ar, out ax, out ay) //else muss 3 sein : Tafel.PrüfRichtungMitHinzuhinzufügen(ar, out ax, out ay) ); if (new_pr != orig_pr) { ar[i, j + r] = !ar[i, j + r]; } else { x = ax; y = ay; replacementsmade = true; } } } } for (var i = 1; i < Tafel.TW - 6; i++) { for (var j = 1; j < Tafel.TH - 1; j++) { var v0 = ar[i + 0, j]; var v1 = ar[i + 1, j]; var v2 = ar[i + 2, j]; var v3 = ar[i + 3, j]; var v4 = ar[i + 4, j]; if ((v0 == v1) && (v0 == v2) && (v0 == v3) && (v0 == v4)) { var r = rand.Next(0, 5); ar[i + r, j] = !ar[i + r, j]; var new_pr = (generate == 2) ? Tafel.PrüfRichtungMitHinzufügen(ar, out ax, out ay) : ( (generate == 1) ? Tafel.PrüfRichtung(ar, out ax, out ay) //else muss 3 sein : Tafel.PrüfRichtungMitHinzuhinzufügen(ar, out ax, out ay) ); if (new_pr != orig_pr) { ar[i + r, j] = !ar[i + r, j]; } else { x = ax; y = ay; replacementsmade = true; } } } } for (var i = 1; i < Tafel.TW - 1; i++) { for (var j = 1; j < Tafel.TH - 6; j++) { var v0 = ar[i, j + 0]; var v1 = ar[i, j + 1]; var v2 = ar[i, j + 2]; var v3 = ar[i, j + 3]; var v4 = ar[i, j + 4]; if ((v0 == v1) && (v0 == v2) && (v0 == v3) && (v0 == v4)) { var r = rand.Next(0, 5); ar[i, j + r] = !ar[i, j + r]; var new_pr = (generate == 2) ? Tafel.PrüfRichtungMitHinzufügen(ar, out ax, out ay) : ( (generate == 1) ? Tafel.PrüfRichtung(ar, out ax, out ay) //else muss 3 sein : Tafel.PrüfRichtungMitHinzuhinzufügen(ar, out ax, out ay) ); if (new_pr != orig_pr) { ar[i, j + r] = !ar[i, j + r]; } else { x = ax; y = ay; replacementsmade = true; } } } } return(replacementsmade); }