Hi Martin,mar wrote:I made a lot of subtle design mistakes myself, ... a poor choice of square numbering (I have bit 0 = A8 and bit 63 = H1).
The latter is problematic in that I have to number ranks in reverse order, i.e. rank1 is 7 and rank8 is 0 (to keep things simple).
No problem except that I can't compare ranks directly like if (a<b) ...
Martin
I have the same square numbering and I do not consider it a mistake. I wrote a simple macro
#define CHESS_RANK(rank) (7 - (rank))
using the macro, I can compare CHESS_RANKs directly.
If you write:
if ( CHESS_RANK(a) < CHESS_RANK(b) )
the macro expands to:
if ( (7 - (a)) < (7 - (b)) )
and now, when you compile, a good optimizer will eliminate the useless subtraction transforming it to:
if ( -a < -b )
and now the optimizer is smart enough to realize that this can be transformed (ie: optimized again) into:
if ( a > b )
which means that the macro will execute with no delay. Best of all, your original source code is now clear and agrees with normal chess convention.
Ron
