Why the distance is rowDelta * rowDelta + colDelta * colDelta?
I think that the distance should be rowDelta + colDelta, isn't it?
The starter package looks like this:
- Code: Select all
/**
* Calculates distance between two locations on the game map.
*
* @param t1 one location on the game map
* @param t2 another location on the game map
*
* @return distance between <code>t1</code> and <code>t2</code>
*/
public int getDistance(Tile t1, Tile t2) {
int rowDelta = Math.abs(t1.getRow() - t2.getRow());
int colDelta = Math.abs(t1.getCol() - t2.getCol());
rowDelta = Math.min(rowDelta, rows - rowDelta);
colDelta = Math.min(colDelta, cols - colDelta);
return rowDelta * rowDelta + colDelta * colDelta; // is that right?
}