I am trying to understand pathfinding to finish the medium puzzles and arm myself for the hard ones. I use C# and have a question to the pathfinding tutorial provided by CodinGame (url: http://codingame.com/direct-puzzle/path-finding ).
Question 1: Cell as datatype?
In the pseudo code, they refer to “cell” as a datatye:
Add start cell to the queue
While the queue is not empty:
Get a cell E from the queue
[...]
What is th best way to represent this cell. I have been struggling with this a little (for example in the bender challenge or in the codingame optimisation super secret stuff) where I wanted in both case to pair integers. I ended up working with 2 or 3 or 4 integers as scalar instead of a single value representing them (for example an array of 4 values).
I prefer having:
int x;
int y;
int z;
int t;
string[,,,] Map;
string location;
(...)
location = Map[x, y, z, t];
than
int[] coordinates = new int[4];
string[,,,] Map;
string location;
(...)
location = Map(coordinates[0], coordinates[1], coordinates[2], coordinates[3]);
Is that the right approach? Of should I create a coordinate class with public X, Y, Z and T?
Coordinate coord = new Coordinate(...);
location = Map(coord.X, coord.Y, coord.Z, coord.T);
Question 2: How to test that a cell have not been tested yet?
The tutorial mentions:
For each neighbor V of E (UP, DOWN, RIGHT, LEFT):
If V not yet tested and is valid
(...)
Do I keep a list of all existing cells?
List<Coordinate> coordList = new List<Coordinate>();
(...)
Coordinate coord = new Coordinate(...);
if (!coordList.Exists(x => x == coord))
{
coordList.Add(coord);
//todo enqueue
}
If this is the right approach, this means my class has to contain:
public override bool Equals(Object obj)
{...}
public override int GetHashCode()
{...}
public static bool operator == (Coordinate a, Coordinate b)
{...}
public static bool operator != (Coordinate a, Coordinate b)
{...}
How would I define my Hashcode?
Am I generally thinking in the right direction?
Thanks in advance