Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Manhattan distance is used to the center in chess code that uses an 0x88 board .

0x88 board is 128 square.

public static final byte DISTANCE[] = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        0, 7, 6, 7, 0, 0, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 0, 7, 6, 5, 6, 
        7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        0, 7, 6, 5, 4, 5, 6, 7, 0, 0, 
        0, 0, 0, 0, 0, 0, 7, 6, 5, 4, 
        3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 
        0, 7, 6, 5, 4, 3, 2, 3, 4, 5, 
        6, 7, 0, 0, 0, 0, 7, 6, 5, 4, 
        3, 2, 1, 2, 3, 4, 5, 6, 7, 0, 
        0, 7, 6, 5, 4, 3, 2, 1, 0, 1, 
        2, 3, 4, 5, 6, 7, 0, 0, 7, 6, 
        5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 
        7, 0, 0, 0, 0, 7, 6, 5, 4, 3, 
        2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 
        0, 0, 7, 6, 5, 4, 3, 4, 5, 6, 
        7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 
        6, 5, 4, 5, 6, 7, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 0, 7, 6, 5, 6, 
        7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        0, 0, 0, 7, 6, 7, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 0
    };

Is there any other faster method instead of 0x88 to find distance?

share|improve this question
1  
Basic mathematics? If you don't understand how to calculate the manhattan distance you need to go back and read those articles on manhattan distance because they said how to calculate it. –  doppelgreener Jun 30 '12 at 11:11
    
In simple words manhattan distance is going squares of corners,I got that. Any other faster method? –  rajeshverma423 Jun 30 '12 at 11:29
3  
You're new to this site. I suggest you have a look at other up-voted questions to understand how to ask good questions. Good questions get excellent answers. –  ApoorvaJ Jun 30 '12 at 12:53

1 Answer 1

To make sure you know how Manhattan Distance works

Manhattan distance is the sum of the total difference along each axis. In regular geometry you use Pythagoras' theorem:

where a and b are the difference along the x and y axes, and c is the total distance between the points.

In Taxicab geometry you don't need to square it. It's extremely simple. The distance between one point and another is just the sum of the distance along each axis. In 2D:

x difference + y difference = Manhattan distance

The fast method to calculate this

Create a function which takes two points and calculates the above. If you don't know how to do that, you need to go find a tutorial and start learning your programming language through it.

share|improve this answer
    
+1 for not banging your head against the wall after reading his comment :D –  Ali.S Jun 30 '12 at 12:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.