Skip to content

Instantly share code, notes, and snippets.

@general-games
Created October 24, 2023 20:40
Show Gist options
  • Select an option

  • Save general-games/79a3fb164298cd59e3964199c4c77d8d to your computer and use it in GitHub Desktop.

Select an option

Save general-games/79a3fb164298cd59e3964199c4c77d8d to your computer and use it in GitHub Desktop.
Removing invalid cells from movement path
//Add this code at line 56-57 in the MovementAction Script
//Calculate all paths and add to movementPaths
var invalidPathCells = gameGrid.cells.Where(c => !validation.Validate(c, this));
var (distances, previous) = new Dijkstra<Cell>().GetPaths(gameGrid.Graph, invalidPathCells.Select(c => c.gridPosition.index).ToArray() ,gameGrid.Size, Entity.GridPosition.index);
@erikandre
Copy link
Copy Markdown

With later versions of Gridr the following code works:

    //Calculate all paths and add to movementPaths
    var invalidPathCells = Entity.GameGrid.cells
        .Where(c => !validation.Validate(c, this))
        .Select(c => c.gridPosition.index)
        .ToArray();
    var (distances, previous) = new Dijkstra<Cell>().GetPaths(Entity.GameGrid.Graph, invalidPathCells, Entity.GameGrid.Size, Entity.GridPosition.index);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment