Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 0 additions & 198 deletions Controls/PathFinding/2dTileBasedPathFinding/Grid.cs

This file was deleted.

21 changes: 21 additions & 0 deletions Controls/PathFinding/2dTileBasedPathFinding/GridI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Represent a grid of nodes we can search paths on.
* Based on code and tutorial by Sebastian Lague (https://www.youtube.com/channel/UCmtyQOKKmrMVaKuRXz02jbQ).
*
* Author: Ronen Ness.
* Since: 2016.
*/
using System.Collections.Generic;

namespace NesScripts.Controls.PathFind {

/// <summary>
/// A 2D grid of nodes we use to find paths with the PathFinding class.
/// The grid supplies Nodes which mark tiles with traversal costs.
/// The grid can be square or hexagonal (using offset coordinate system).
/// </summary>
public interface GridI {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not call it IGrid?

Node GetNode (int x, int y);
IEnumerable<Node> GetNeighbours (Node currentNode, Pathfinding.DistanceType distance);
}
}
12 changes: 6 additions & 6 deletions Controls/PathFinding/2dTileBasedPathFinding/PathFinding.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public enum DistanceType
/// <summary>
/// Find a path between two points.
/// </summary>
/// <param name="grid">Grid to search.</param>
/// <param name="grid">GridI to search.</param>
/// <param name="startPos">Starting position.</param>
/// <param name="targetPos">Ending position.</param>
/// <param name="distance">The type of distance, Euclidean or Manhattan.</param>
/// <param name="ignorePrices">If true, will ignore tile price (how much it "cost" to walk on).</param>
/// <returns>List of points that represent the path to walk.</returns>
public static List<Point> FindPath(Grid grid, Point startPos, Point targetPos, DistanceType distance = DistanceType.Euclidean, bool ignorePrices = false)
public static List<Point> FindPath(GridI grid, Point startPos, Point targetPos, DistanceType distance = DistanceType.Euclidean, bool ignorePrices = false)
{
// find path
List<Node> nodes_path = _ImpFindPath(grid, startPos, targetPos, distance, ignorePrices);
Expand All @@ -69,10 +69,10 @@ public static List<Point> FindPath(Grid grid, Point startPos, Point targetPos, D
/// <param name="distance">The type of distance, Euclidean or Manhattan.</param>
/// <param name="ignorePrices">If true, will ignore tile price (how much it "cost" to walk on).</param>
/// <returns>List of grid nodes that represent the path to walk.</returns>
private static List<Node> _ImpFindPath(Grid grid, Point startPos, Point targetPos, DistanceType distance = DistanceType.Euclidean, bool ignorePrices = false)
private static List<Node> _ImpFindPath(GridI grid, Point startPos, Point targetPos, DistanceType distance = DistanceType.Euclidean, bool ignorePrices = false)
{
Node startNode = grid.nodes[startPos.x, startPos.y];
Node targetNode = grid.nodes[targetPos.x, targetPos.y];
Node startNode = grid.GetNode(startPos.x, startPos.y);
Node targetNode = grid.GetNode(targetPos.x, targetPos.y);

List<Node> openSet = new List<Node>();
HashSet<Node> closedSet = new HashSet<Node>();
Expand Down Expand Up @@ -127,7 +127,7 @@ private static List<Node> _ImpFindPath(Grid grid, Point startPos, Point targetPo
/// <param name="startNode">Starting node.</param>
/// <param name="endNode">Ending (target) node.</param>
/// <returns>Retraced path between nodes.</returns>
private static List<Node> RetracePath(Grid grid, Node startNode, Node endNode)
private static List<Node> RetracePath(GridI grid, Node startNode, Node endNode)
{
List<Node> path = new List<Node>();
Node currentNode = endNode;
Expand Down
Loading