I have been working in the past weeks on a multiplayer HTML5 game, using nodejs
and websockets
.
I've been stuck in this problem for a little while.
Imagine that I have this tilesheet map implemented with an array (as shown below).
1 or brown tiles - there is an obstacle in the way and the player can not pass through it.
0 or green tiles - are free paths where the player is allowed to move.
Access any tile on the map by calling:
array[x][y]
I would like to create the fastest algorithm possible to find out the shortest route (if there is one) between two points of the map. How would you approach this problem? I know this is common problem.
Example:
Player at the position (1,7) fires a bullet with some AI that will toward the enemy player at the position (6,0). Bullet has to calculate the shortest route between the 2 players and if there aren′t any it would just explode against a wall.
Question:
How to efficiently find the shortest route between two points?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…