I am making a 2D map of an array, for example:
* 0 1 2 3 4 5 6
0
1
2
3
4
It's a game. “T” is the Troll, and “P” is the Player. The troll chases the player in this game. Suppose now the player will not move. The position (row, column) of the Troll is (3.2) and Player (0.5)
A troll can chase a player, heading up and right. This means that in order to reach position P, only 3 steps are required:
(3,2)->(2,3)->(1,4)->(0,5)
But, when I use the Euclidean distance formula:
(int) Math.floor(Math.sqrt(Math.pow((0-3) , 2) + Math.pow((5-2) , 2))) ;
it takes 4 steps.
I am so confused by the formula Distance. I can not use it in this situation? But in some cases, he takes the right steps.
Hope someone can explain this problem, thanks.
annie