public static void Solve() { AppData.AppState = AppData.AppStates.LongTask; //MazePoint[,] precMatrix; //int[,] distMatrix; var solvePath = new List <MazePoint>(); var heatMatrix = HeatMap.Generate(MazeData.EntrancePoint.X, MazeData.EntrancePoint.Y, false, MazeData.ExitPoint.X, MazeData.ExitPoint.Y); var currentPoint = new MazePoint(MazeData.ExitPoint.X, MazeData.ExitPoint.Y); while (currentPoint != null) { var lastPoint = currentPoint; if (AppData.AppState == AppData.AppStates.Idle) { break; } if (heatMatrix[currentPoint.X, currentPoint.Y].Preceding != null && (Math.Abs(currentPoint.X - heatMatrix[currentPoint.X, currentPoint.Y].Preceding.X) > 1 || Math.Abs(currentPoint.Y - heatMatrix[currentPoint.X, currentPoint.Y].Preceding.Y) > 1)) { var extraWeavePoint = new MazePoint((currentPoint.X + heatMatrix[currentPoint.X, currentPoint.Y].Preceding.X) / 2, (currentPoint.Y + heatMatrix[currentPoint.X, currentPoint.Y].Preceding.Y) / 2); solvePath.Add(extraWeavePoint); } solvePath.Add(currentPoint); currentPoint = heatMatrix[currentPoint.X, currentPoint.Y].Preceding; //if (AnimateCheckBox.Checked && Convert.ToInt32(DelayTextBox.Text) > 0) // Thread.Sleep(Convert.ToInt32(DelayTextBox.Text)); } //foreach (var solvePoint in solvePath) for (var i = 1; i < solvePath.Count - 1; i++) { MazeData.MazeMatrix[solvePath[i].X, solvePath[i].Y].Display = MazeData.MazeColors[CellState.AutoPath]; } /*if (!AnimateCheckBox.Checked) * { * foreach (var solvePoint in solvePath) * DrawCell(solvePoint.X, solvePoint.Y, MazeColors.AutoPath.Brush); * RefreshPictureBox(); * }*/ /*BeginInvoke(new MethodInvoker(() => * { * EnableButtons(); * GameStepsLabel.Visible = true; * GameStepsLabel.Text = @"Shortest path - " + solvePath.Count; * }));*/ }
public static void Solve() { AppData.AppState = AppData.AppStates.LongTask; //MazePoint[,] precMatrix; //int[,] distMatrix; var solvePath = new List<MazePoint>(); var heatMatrix = HeatMap.Generate(MazeData.EntrancePoint.X, MazeData.EntrancePoint.Y, false, MazeData.ExitPoint.X, MazeData.ExitPoint.Y); var currentPoint = new MazePoint(MazeData.ExitPoint.X, MazeData.ExitPoint.Y); while (currentPoint != null) { var lastPoint = currentPoint; if (AppData.AppState == AppData.AppStates.Idle) break; if (heatMatrix[currentPoint.X, currentPoint.Y].Preceding != null && (Math.Abs(currentPoint.X - heatMatrix[currentPoint.X, currentPoint.Y].Preceding.X) > 1 || Math.Abs(currentPoint.Y - heatMatrix[currentPoint.X, currentPoint.Y].Preceding.Y) > 1)) { var extraWeavePoint = new MazePoint((currentPoint.X + heatMatrix[currentPoint.X, currentPoint.Y].Preceding.X) / 2, (currentPoint.Y + heatMatrix[currentPoint.X, currentPoint.Y].Preceding.Y) / 2); solvePath.Add(extraWeavePoint); } solvePath.Add(currentPoint); currentPoint = heatMatrix[currentPoint.X, currentPoint.Y].Preceding; //if (AnimateCheckBox.Checked && Convert.ToInt32(DelayTextBox.Text) > 0) // Thread.Sleep(Convert.ToInt32(DelayTextBox.Text)); } //foreach (var solvePoint in solvePath) for(var i = 1; i < solvePath.Count - 1; i++) MazeData.MazeMatrix[solvePath[i].X, solvePath[i].Y].Display = MazeData.MazeColors[CellState.AutoPath]; /*if (!AnimateCheckBox.Checked) { foreach (var solvePoint in solvePath) DrawCell(solvePoint.X, solvePoint.Y, MazeColors.AutoPath.Brush); RefreshPictureBox(); }*/ /*BeginInvoke(new MethodInvoker(() => { EnableButtons(); GameStepsLabel.Visible = true; GameStepsLabel.Text = @"Shortest path - " + solvePath.Count; }));*/ }
public static HeatPoint[,] Generate(int fromX, int fromY, bool draw, int breakOnX, int breakOnY) { var _mazeWidth = MazeData.MazeSize; var _mazeHeight = MazeData.MazeSize; //distMatrix = new int[_mazeWidth, _mazeHeight]; //precMatrix = new MazePoint[_mazeWidth, _mazeHeight]; var heatMatrix = new HeatPoint[_mazeWidth, _mazeHeight]; for (int i = 0; i < _mazeWidth; i++) { for (int j = 0; j < _mazeHeight; j++) { heatMatrix[i, j] = new HeatPoint(); } } var point = new MazePoint(fromX, fromY); var row = new LinkedList <MazePoint>(); row.AddFirst(point); var endPointFound = false; var count = 1; var newCount = -1; var index = -1; for (var curr = row.First; curr != null; curr = curr.Next) { index++; if (AppData.AppState == AppData.AppStates.Idle) { break; } if (index == count) { newCount = row.Count; } if (index == newCount) { for (var i = 0; i < count; i++) { row.RemoveFirst(); } index -= count; count = newCount - count; newCount = row.Count; } var adjPoints = MazeData.GetAdjPoints(curr.Value); foreach (var adjPoint in adjPoints) { MazePoint goToPoint; /*if (MazeData.MazeMatrix[adjPoint.X, adjPoint.Y] == CellState.HorWeave || * MazeData.MazeMatrix[adjPoint.X, adjPoint.Y] == CellState.VertWeave) * { * goToPoint = new MazePoint(adjPoint.X + (adjPoint.X - curr.Value.X), * adjPoint.Y + (adjPoint.Y - curr.Value.Y)); * } * else*/ goToPoint = adjPoint; if (row.Contains(goToPoint)) { continue; } row.AddLast(goToPoint); heatMatrix[goToPoint.X, goToPoint.Y].Preceding = curr.Value; heatMatrix[goToPoint.X, goToPoint.Y].Distance = heatMatrix[curr.Value.X, curr.Value.Y].Distance + 1; if (breakOnX > 0 && breakOnY > 0 && goToPoint.X == breakOnX && goToPoint.Y == breakOnY) { endPointFound = true; break; } } //if (AnimateCheckBox.Checked && Convert.ToInt32(DelayTextBox.Text) > 0) // Thread.Sleep(Convert.ToInt32(DelayTextBox.Text)); if (endPointFound) { break; } } /*for (var i = 0; i < _mazeWidth; i++) * { * for (var j = 0; j < _mazeHeight; j++) * { * switch (_mazeMatrix[i, j]) * { * case CellState.VertWeave: * distMatrix[i, j] = (distMatrix[i + 1, j] + distMatrix[i - 1, j]) / 2; * break; * case CellState.HorWeave: * distMatrix[i, j] = (distMatrix[i, j + 1] + distMatrix[i, j - 1]) / 2; * break; * } * } * }*/ if (!draw) { return(heatMatrix); } var maxDist = 1; for (var i = 0; i < _mazeWidth; i++) { for (var j = 0; j < _mazeHeight; j++) { if (heatMatrix[i, j].Distance > maxDist) { maxDist = heatMatrix[i, j].Distance; } } } for (var i = 0; i < _mazeWidth; i++) { for (var j = 0; j < _mazeHeight; j++) { if (MazeData.MazeMatrix[i, j] == null || MazeData.MazeMatrix[i, j].State == CellState.Wall) { continue; } var red = heatMatrix[i, j].Distance * 255 / maxDist; Color c; if (heatMatrix[i, j].Distance < 1) { c = MazeData.MazeColors[CellState.Entrance]; } else if (heatMatrix[i, j].Distance > maxDist - 1) { c = MazeData.MazeColors[CellState.Furthest]; } else { c = Color.FromRgba(50 * 256 * 256 + 50 * 256 + red); } MazeData.MazeMatrix[i, j].Display = c; } } return(heatMatrix); }
public override void GenerateMaze(int size, ref double animationDelay, ref int behaviorValue) { MazeData.CreateEmpty(size); //var loopValue = 0; //var weaveValue = 0; var useInfluences = false; var leftInfluence = 0; var rightInfluence = 0; var upInfluence = 0; var downInfluence = 0; var _mazeWidth = size; var _mazeHeight = size; var row = _rng.Next(0, _mazeWidth/2 - 1)*2 + 1; var col = _rng.Next(0, _mazeHeight/2 - 1)*2 + 1; var path = new List<MazePoint> {new MazePoint(row, col)}; MazeData.MazeMatrix[row, col].State = CellState.Walkway; AppData.AppState = AppData.AppStates.LongTask; //var permitloop = false; var success = true; var moveVect = MazeData.Directions[-1]; while (path.Count > 0 && AppData.AppState == AppData.AppStates.LongTask) { int currIndex; if (_rng.Next(1, 1001) < behaviorValue) currIndex = _rng.Next(0, path.Count); else currIndex = path.Count - 1; row = path[currIndex].X; col = path[currIndex].Y; //var origRow = row; //var origCol = col; //success = TryDig(ref row, ref col, out moveVect, _rng.Next(0, 1001) < weaveValue, false, useInfluences ? new List<int> { leftInfluence, rightInfluence, upInfluence, downInfluence } : null); var rand = 0; //var val = 0; var probabilities = useInfluences ? new List<int> {leftInfluence, rightInfluence, upInfluence, downInfluence} : null; if (probabilities == null) probabilities = new List<int> {1, 1, 1, 1}; var dirCopy = new List<MazePoint>(MazeData.Directions.Values); for (var i = 0; i < 4; i++) { if (probabilities.All(x => x == 0)) rand = _rng.Next(0, probabilities.Count); else for (var j = 0; j < probabilities.Count; j++) { var leftProb = 0; for (var k = j; k < probabilities.Count; k++) leftProb += probabilities[k]; var currProb = (1000000*probabilities[j])/leftProb; if (_rng.Next(1, 1000001) < currProb) { rand = j; break; } } var direction = dirCopy[rand]; if (MazeData.IsPointInMaze(row + direction.X*2, col + direction.Y*2)) { // Looping //if (allowLoop) //{ // if (MazeData.MazeMatrix[row + direction.X, col + direction.Y] != CellState.Wall) continue; // MazeData.MazeMatrix[row + direction.X, col + direction.Y] = CellState.Walkway; // moveVector = new MyPoint(direction.X * 2, direction.Y * 2); // row += moveVector.X; // col += moveVector.Y; // return true; //} // Simple generation if (MazeData.MazeMatrix[row + direction.X*2, col + direction.Y*2].State == CellState.Wall) { MazeData.MazeMatrix[row + direction.X, col + direction.Y].State = CellState.Walkway; MazeData.MazeMatrix[row + direction.X, col + direction.Y].Display = MazeData.MazeColors[CellState.Generating]; MazeData.MazeMatrix[row + direction.X*2, col + direction.Y*2].State = CellState.Walkway; MazeData.MazeMatrix[row + direction.X * 2, col + direction.Y * 2].Display = MazeData.MazeColors[CellState.Generating]; moveVect = new MazePoint(direction.X*2, direction.Y*2); row += moveVect.X; col += moveVect.Y; success = true; break; } // Weaving //if (allowWeave && _mazeRectangle.Contains(row + direction.X * 4, col + direction.Y * 4) // && _mazeMatrix[row + direction.X * 2, col + direction.Y * 2] == CellState.Walkway // && _mazeMatrix[row + direction.X * 4, col + direction.Y * 4] == CellState.Wall // && _mazeMatrix[row + direction.X, col + direction.Y] == CellState.Wall) //{ // _mazeMatrix[row + direction.X * 2, col + direction.Y * 2] = // direction.Y == 0 ? CellState.HorWeave : CellState.VertWeave; // _mazeMatrix[row + direction.X, col + direction.Y] = CellState.Walkway; // _mazeMatrix[row + direction.X * 3, col + direction.Y * 3] = CellState.Walkway; // _mazeMatrix[row + direction.X * 4, col + direction.Y * 4] = CellState.Walkway; // moveVector = new MyPoint(direction.X * 4, direction.Y * 4); // row += moveVector.X; // col += moveVector.Y; // return true; //} } dirCopy.RemoveAt(rand); try { probabilities.RemoveAt(rand); } catch { } if (i == 3) { //moveVect = MazeData.Directions[-1]; success = false; } } // Failed to generate if (success) { //permitloop = true; path.Add(new MazePoint(row, col)); } else { //if (permitloop && _rng.Next(0, 101) < loopValue) //{ // TryDig(ref row, ref col, out moveVect, false, true, null); // if (AnimateCheckBox.Checked) // { // var rowDiff = row - origRow; // var colDiff = col - origCol; // if (rowDiff != 0) // DrawCell(origRow + (rowDiff > 0 ? 1 : -1), origCol, MazeColors.Walkway.Brush); // else if (colDiff != 0) // DrawCell(origRow, origCol + (colDiff > 0 ? 1 : -1), MazeColors.Walkway.Brush); // RefreshPictureBox(row, col, 1); // } //} //permitloop = false; for (var i = -1; i < 4; i++) for (var j = 1; j < 2; j++) { var x = row + MazeData.Directions[i].X * j; var y = col + MazeData.Directions[i].Y * j; if (MazeData.MazeMatrix[x, y] != null && MazeData.MazeMatrix[x, y].State != CellState.Wall) MazeData.MazeMatrix[x, y].Display = MazeData.MazeColors[CellState.Walkway]; } path.RemoveAt(currIndex); } if (animationDelay > 0) Utils.Sleep(animationDelay); } //GC.Collect(); MakeEntranceExit(); AppData.AppState = AppData.AppStates.Idle; }
public static bool IsPointInMaze(MazePoint point) { return(IsPointInMaze(point.X, point.Y)); }
public static IEnumerable <MazePoint> GetAdjPoints(MazePoint point) { return(GetAdjPoints(point.X, point.Y)); }
public override void GenerateMaze(int size, ref double animationDelay, ref int behaviorValue) { MazeData.CreateEmpty(size); //var loopValue = 0; //var weaveValue = 0; var useInfluences = false; var leftInfluence = 0; var rightInfluence = 0; var upInfluence = 0; var downInfluence = 0; var _mazeWidth = size; var _mazeHeight = size; var row = _rng.Next(0, _mazeWidth / 2 - 1) * 2 + 1; var col = _rng.Next(0, _mazeHeight / 2 - 1) * 2 + 1; var path = new List <MazePoint> { new MazePoint(row, col) }; MazeData.MazeMatrix[row, col].State = CellState.Walkway; AppData.AppState = AppData.AppStates.LongTask; //var permitloop = false; var success = true; var moveVect = MazeData.Directions[-1]; while (path.Count > 0 && AppData.AppState == AppData.AppStates.LongTask) { int currIndex; if (_rng.Next(1, 1001) < behaviorValue) { currIndex = _rng.Next(0, path.Count); } else { currIndex = path.Count - 1; } row = path[currIndex].X; col = path[currIndex].Y; //var origRow = row; //var origCol = col; //success = TryDig(ref row, ref col, out moveVect, _rng.Next(0, 1001) < weaveValue, false, useInfluences ? new List<int> { leftInfluence, rightInfluence, upInfluence, downInfluence } : null); var rand = 0; //var val = 0; var probabilities = useInfluences ? new List <int> { leftInfluence, rightInfluence, upInfluence, downInfluence } : null; if (probabilities == null) { probabilities = new List <int> { 1, 1, 1, 1 } } ; var dirCopy = new List <MazePoint>(MazeData.Directions.Values); for (var i = 0; i < 4; i++) { if (probabilities.All(x => x == 0)) { rand = _rng.Next(0, probabilities.Count); } else { for (var j = 0; j < probabilities.Count; j++) { var leftProb = 0; for (var k = j; k < probabilities.Count; k++) { leftProb += probabilities[k]; } var currProb = (1000000 * probabilities[j]) / leftProb; if (_rng.Next(1, 1000001) < currProb) { rand = j; break; } } } var direction = dirCopy[rand]; if (MazeData.IsPointInMaze(row + direction.X * 2, col + direction.Y * 2)) { // Looping //if (allowLoop) //{ // if (MazeData.MazeMatrix[row + direction.X, col + direction.Y] != CellState.Wall) continue; // MazeData.MazeMatrix[row + direction.X, col + direction.Y] = CellState.Walkway; // moveVector = new MyPoint(direction.X * 2, direction.Y * 2); // row += moveVector.X; // col += moveVector.Y; // return true; //} // Simple generation if (MazeData.MazeMatrix[row + direction.X * 2, col + direction.Y * 2].State == CellState.Wall) { MazeData.MazeMatrix[row + direction.X, col + direction.Y].State = CellState.Walkway; MazeData.MazeMatrix[row + direction.X, col + direction.Y].Display = MazeData.MazeColors[CellState.Generating]; MazeData.MazeMatrix[row + direction.X * 2, col + direction.Y * 2].State = CellState.Walkway; MazeData.MazeMatrix[row + direction.X * 2, col + direction.Y * 2].Display = MazeData.MazeColors[CellState.Generating]; moveVect = new MazePoint(direction.X * 2, direction.Y * 2); row += moveVect.X; col += moveVect.Y; success = true; break; } // Weaving //if (allowWeave && _mazeRectangle.Contains(row + direction.X * 4, col + direction.Y * 4) // && _mazeMatrix[row + direction.X * 2, col + direction.Y * 2] == CellState.Walkway // && _mazeMatrix[row + direction.X * 4, col + direction.Y * 4] == CellState.Wall // && _mazeMatrix[row + direction.X, col + direction.Y] == CellState.Wall) //{ // _mazeMatrix[row + direction.X * 2, col + direction.Y * 2] = // direction.Y == 0 ? CellState.HorWeave : CellState.VertWeave; // _mazeMatrix[row + direction.X, col + direction.Y] = CellState.Walkway; // _mazeMatrix[row + direction.X * 3, col + direction.Y * 3] = CellState.Walkway; // _mazeMatrix[row + direction.X * 4, col + direction.Y * 4] = CellState.Walkway; // moveVector = new MyPoint(direction.X * 4, direction.Y * 4); // row += moveVector.X; // col += moveVector.Y; // return true; //} } dirCopy.RemoveAt(rand); try { probabilities.RemoveAt(rand); } catch { } if (i == 3) { //moveVect = MazeData.Directions[-1]; success = false; } } // Failed to generate if (success) { //permitloop = true; path.Add(new MazePoint(row, col)); } else { //if (permitloop && _rng.Next(0, 101) < loopValue) //{ // TryDig(ref row, ref col, out moveVect, false, true, null); // if (AnimateCheckBox.Checked) // { // var rowDiff = row - origRow; // var colDiff = col - origCol; // if (rowDiff != 0) // DrawCell(origRow + (rowDiff > 0 ? 1 : -1), origCol, MazeColors.Walkway.Brush); // else if (colDiff != 0) // DrawCell(origRow, origCol + (colDiff > 0 ? 1 : -1), MazeColors.Walkway.Brush); // RefreshPictureBox(row, col, 1); // } //} //permitloop = false; for (var i = -1; i < 4; i++) { for (var j = 1; j < 2; j++) { var x = row + MazeData.Directions[i].X * j; var y = col + MazeData.Directions[i].Y * j; if (MazeData.MazeMatrix[x, y] != null && MazeData.MazeMatrix[x, y].State != CellState.Wall) { MazeData.MazeMatrix[x, y].Display = MazeData.MazeColors[CellState.Walkway]; } } } path.RemoveAt(currIndex); } if (animationDelay > 0) { Utils.Sleep(animationDelay); } } //GC.Collect(); MakeEntranceExit(); AppData.AppState = AppData.AppStates.Idle; } /*private bool TryDig(ref int row, ref int col, out MazePoint moveVector, bool allowWeave, bool allowLoop, List<int> probabilities) * { * var rand = 0; * //var val = 0; * if (probabilities == null) * probabilities = new List<int> { 1, 1, 1, 1 }; * var dirCopy = new List<MazePoint>(MazeData.Directions.Values); * * for (var i = 0; i < 4; i++) * { * if (probabilities.All(x => x == 0)) * rand = _rng.Next(0, probabilities.Count); * else * for (var j = 0; j < probabilities.Count; j++) * { * var leftProb = 0; * for (var k = j; k < probabilities.Count; k++) * leftProb += probabilities[k]; * var currProb = (1000000 * probabilities[j]) / leftProb; * if (_rng.Next(1, 1000001) < currProb) * { * rand = j; * break; * } * } * * var direction = dirCopy[rand]; * * if (MazeData.IsPointInMaze(row + direction.X*2, col + direction.Y*2)) * { * // Looping * //if (allowLoop) * //{ * // if (MazeData.MazeMatrix[row + direction.X, col + direction.Y] != CellState.Wall) continue; * // MazeData.MazeMatrix[row + direction.X, col + direction.Y] = CellState.Walkway; * // moveVector = new MyPoint(direction.X * 2, direction.Y * 2); * // row += moveVector.X; * // col += moveVector.Y; * // return true; * //} * * // Simple generation * if (MazeData.MazeMatrix[row + direction.X * 2, col + direction.Y * 2].State == CellState.Wall) * { * MazeData.MazeMatrix[row + direction.X, col + direction.Y].State = CellState.Walkway; * MazeData.MazeMatrix[row + direction.X * 2, col + direction.Y * 2].State = CellState.Walkway; * moveVector = new MazePoint(direction.X * 2, direction.Y * 2); * row += moveVector.X; * col += moveVector.Y; * return true; * } * * // Weaving * //if (allowWeave && _mazeRectangle.Contains(row + direction.X * 4, col + direction.Y * 4) * // && _mazeMatrix[row + direction.X * 2, col + direction.Y * 2] == CellState.Walkway * // && _mazeMatrix[row + direction.X * 4, col + direction.Y * 4] == CellState.Wall * // && _mazeMatrix[row + direction.X, col + direction.Y] == CellState.Wall) * //{ * // _mazeMatrix[row + direction.X * 2, col + direction.Y * 2] = * // direction.Y == 0 ? CellState.HorWeave : CellState.VertWeave; * // _mazeMatrix[row + direction.X, col + direction.Y] = CellState.Walkway; * // _mazeMatrix[row + direction.X * 3, col + direction.Y * 3] = CellState.Walkway; * // _mazeMatrix[row + direction.X * 4, col + direction.Y * 4] = CellState.Walkway; * // moveVector = new MyPoint(direction.X * 4, direction.Y * 4); * // row += moveVector.X; * // col += moveVector.Y; * // return true; * //} * } * dirCopy.RemoveAt(rand); * try { probabilities.RemoveAt(rand); } * catch { } * // TODO: fix random error * } * // Failed to generate * moveVector = MazeData.Directions[-1]; * return false; * }*/ }
public static bool IsPointInMaze(MazePoint point) { return IsPointInMaze(point.X, point.Y); }
public static IEnumerable<MazePoint> GetAdjPoints(MazePoint point) { return GetAdjPoints(point.X, point.Y); }
public static HeatPoint[,] Generate(int fromX, int fromY, bool draw, int breakOnX, int breakOnY) { var _mazeWidth = MazeData.MazeSize; var _mazeHeight = MazeData.MazeSize; //distMatrix = new int[_mazeWidth, _mazeHeight]; //precMatrix = new MazePoint[_mazeWidth, _mazeHeight]; var heatMatrix = new HeatPoint[_mazeWidth,_mazeHeight]; for (int i = 0; i < _mazeWidth; i++) for (int j = 0; j < _mazeHeight; j++) heatMatrix[i, j] = new HeatPoint(); var point = new MazePoint(fromX, fromY); var row = new LinkedList<MazePoint>(); row.AddFirst(point); var endPointFound = false; var count = 1; var newCount = -1; var index = -1; for (var curr = row.First; curr != null; curr = curr.Next) { index++; if (AppData.AppState == AppData.AppStates.Idle) break; if (index == count) newCount = row.Count; if (index == newCount) { for (var i = 0; i < count; i++) row.RemoveFirst(); index -= count; count = newCount - count; newCount = row.Count; } var adjPoints = MazeData.GetAdjPoints(curr.Value); foreach (var adjPoint in adjPoints) { MazePoint goToPoint; /*if (MazeData.MazeMatrix[adjPoint.X, adjPoint.Y] == CellState.HorWeave || MazeData.MazeMatrix[adjPoint.X, adjPoint.Y] == CellState.VertWeave) { goToPoint = new MazePoint(adjPoint.X + (adjPoint.X - curr.Value.X), adjPoint.Y + (adjPoint.Y - curr.Value.Y)); } else*/ goToPoint = adjPoint; if (row.Contains(goToPoint)) continue; row.AddLast(goToPoint); heatMatrix[goToPoint.X, goToPoint.Y].Preceding = curr.Value; heatMatrix[goToPoint.X, goToPoint.Y].Distance = heatMatrix[curr.Value.X, curr.Value.Y].Distance + 1; if (breakOnX > 0 && breakOnY > 0 && goToPoint.X == breakOnX && goToPoint.Y == breakOnY) { endPointFound = true; break; } } //if (AnimateCheckBox.Checked && Convert.ToInt32(DelayTextBox.Text) > 0) // Thread.Sleep(Convert.ToInt32(DelayTextBox.Text)); if (endPointFound) break; } /*for (var i = 0; i < _mazeWidth; i++) { for (var j = 0; j < _mazeHeight; j++) { switch (_mazeMatrix[i, j]) { case CellState.VertWeave: distMatrix[i, j] = (distMatrix[i + 1, j] + distMatrix[i - 1, j]) / 2; break; case CellState.HorWeave: distMatrix[i, j] = (distMatrix[i, j + 1] + distMatrix[i, j - 1]) / 2; break; } } }*/ if (!draw) return heatMatrix; var maxDist = 1; for (var i = 0; i < _mazeWidth; i++) for (var j = 0; j < _mazeHeight; j++) if (heatMatrix[i, j].Distance > maxDist) maxDist = heatMatrix[i, j].Distance; for (var i = 0; i < _mazeWidth; i++) { for (var j = 0; j < _mazeHeight; j++) { if (MazeData.MazeMatrix[i, j] == null || MazeData.MazeMatrix[i, j].State == CellState.Wall) continue; var red = heatMatrix[i, j].Distance * 255 / maxDist; Color c; if (heatMatrix[i, j].Distance < 1) c = MazeData.MazeColors[CellState.Entrance]; else if (heatMatrix[i, j].Distance > maxDist - 1) c = MazeData.MazeColors[CellState.Furthest]; else c = Color.FromRgba(50 * 256 * 256 + 50 * 256 + red); MazeData.MazeMatrix[i, j].Display = c; } } return heatMatrix; }