Updating this post, once again.
This time to make things clearer.
I am trying, to parse in a Grid of size 9x9, but this size can change overtime, its not fixed. This is a board game called Quoridor. What I have at my disposal, is a Board class. This provides me with the following, horizontal bool[,], and vertical bool[,], I can loop over each and print out x, y position. But these differ, depending on if its horizontal direction, or vertical direction and position.
The player can move one step ONLY either north, south, west, or east in terms of direction. The other player (human) can put a wall (obstacle) which covers two blocks horizontally or vertically. My automated player has to build a Graph of Nodes from the board, and refresh the Graph based on the changes on the board and its own position. For example, if the player cannot go to left, from current position, then an edge which connects two nodes will be deleted between them, only if caused by an obstacle. And then the BFS will run again against the Graph and return a new position (x, y) which this (automated) player uses and performs its move.
Every single block on the 9x9 grid, will represent one Node in the Graph. Meaning the number of vertices or nodes List in the Graph will be 9x9=81. Each of the Nodes hold a list or 2D array of size 4 for representing North, South, West, and East which could be of a bool type.
Now, I have provided a sample code of the Graph class I wrote along with a Node class. I hope the latest information herein makes it clear. I have already implemented the BFS algorithm. But this part is what I cannot understand correctly. I watched this video for some ideas: https://www.youtube.com/watch?v=KiCBXu4P-2Y
Code
class Graph<T>
{
private int _V;
private List<T>[] _Nodes;
public Graph(int v)
{
_V = v;
_Nodes = new List<T>[v];
for (int i = 0; i < _Nodes.Length; i++)
_Nodes [i] = new List<T>();
}
public IEnumerable<T> Nodes(int v) { return (IEnumerable<T>)_Nodes[v];}
public int V { get => _V; }
public bool EdgeExists(){}
public void AddEdge(Node n, T u, T w){}
public void RemoveEdge(){}
}
and,
class Node<T>
{
private int _E;
private List<T>[] _Adj;
public Node(int e)
{
_E = e;
_Adj = new List<T>[e];
for (int i = 0; i < _Adj.Length; i++)
_Adj [e] = new List<T>();
}
public IEnumerable<T> Adj(int e) { return (IEnumerable<T>)_Adj[e];}
public int E { get => _E; }
public void AddEdge(Node n, T u, T w){}
public void RemoveEdge(T value){}
}
I read the following SO threads:
- How can you make an adjacency matrix which would emulate a 2d grid
- Implementing 2D Grid Network ( Graph ) and Adjacency Matrix of it in C
- Representing a graph with a 2D array
- How can I build a graph from a 2D array?
- Creating an adjacency list graph from a matrix in python
- https://learn.microsoft.com/en-us/previous-versions/ms379574(v=vs.80)?redirectedfrom=MSDN
- How can I make my BFS algorithm run faster?


