JAVA - How to code Node neighbours in a Grid ?
Posted
by ke3pup
on Stack Overflow
See other posts from Stack Overflow
or by ke3pup
Published on 2010-04-21T00:00:35Z
Indexed on
2010/04/21
0:03 UTC
Read the original article
Hit count: 129
java
Hi guys
I'm new to programming and as a School task i need to implement BFS,DFS and A* search algorithms in java to search for a given Goal from a given start position in a Grid of given size, 4x4,8x8..etc
to begin with i don't know how to code the neighbors of all the nodes. For example tile 1 in grid as 2 and 9 as neighbors and Tile 12 has ,141,13,20 as its neighbours but i'm struggling to code that. I need the neighbours part so that i can move from start position to other parts of gird legally by moving horizontally or vertically through the neighbours.
my node class is:
class node {
int value;
LinkedList neighbors;
bool expanded;
}
let's say i'm given a 8x8 grid right, So if i start the program with a grid of size 8x8 right :
1 - my main will func will create an arrayList of nodes for example node
ArrayList test = new ArrayList();
and then using a for loop assign value to all the nodes in arrayList from 1 to 64 (if the grid size was 8x8).
BUT somehow i need t on coding that, if anyone can give me some details i would really appreciate it.
© Stack Overflow or respective owner