From 6e0bb361320376490a99ecb0d4a5421eb4ae9d45 Mon Sep 17 00:00:00 2001 From: Dan Cojocaru Date: Thu, 2 Dec 2021 00:04:10 +0200 Subject: [PATCH] Forgot minor things about IDA* Minor things like avoiding obstacles... --- IDAstar.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/IDAstar.cs b/IDAstar.cs index a02fdd6..2e816ae 100644 --- a/IDAstar.cs +++ b/IDAstar.cs @@ -179,13 +179,26 @@ namespace IdaStar if (!neighbour.IsInsideBox(_board.Count, _board[0].Count)) { continue; } + if (_board[neighbour.Row][neighbour.Column] == CellState.OBSTACLE) { + continue; + } + + if (_board[neighbour.Row][neighbour.Column] == CellState.EMPTY) { + _board[neighbour.Row][neighbour.Column] = CellState.PATH; + } + AlgorithmStep?.Invoke(this); var neighbourF = search(neighbour, cost + increment, threshold); + if (neighbourF < min) { min = neighbourF; } if (min == zero) { break; } + + if (_board[neighbour.Row][neighbour.Column] == CellState.PATH) { + _board[neighbour.Row][neighbour.Column] = CellState.EMPTY; + } } return min;