java - Converting Vertex[] to graph -
i making pacman game , working on ghosts ai. planning on using dijkstra's algorithm pathfinding. problem when game loaded vertexes graph stored in matrix. trying assign each vertex of edges this
for(int x = 0; x<40; x++) { for(int y = 0; y<40; y++) { vertex vertex = map[x][y]; vertex.adjacencies = new edge[]{new edge(map[x-1][y], 1), new edge(map[x+1][y], 1), new edge(map[x][y-1], 1), new edge(map[x][y+1], 1)}; } }
the problem throws array out of bounds exception. how fix without putting in tons of if statements check if current vertex on edge of graph.
one easy way include non-traversable border around edges.
for example, if actual map 40x40, can declare 42x42 array. rows 0 , n non-traversable, columns 0 , n.
you'd still need handle cylindrical travel of pacman between left , right sides.
Comments
Post a Comment