Author: Uri Blass
Date: 05:33:19 04/17/03
Go up one level in this thread
On April 17, 2003 at 04:32:39, Sune Fischer wrote:
>On April 16, 2003 at 22:08:54, Uri Blass wrote:
>
>>I guess that I will first add updating some varaibles and in this case I am
>>going to have 2 functions to update varaibles (one for white to move and one for
>>black to move).
>>
>>I think that 2 functions is more readable than one big function that have a lot
>>of side and 1^side.
>>
>>Maybe I should try also to save memory by using less memory in functions that I
>>call only one time.
>>
>>Here is one example for a function that I call only in setup position.
>>You can see that I have a similiar pattern in case that the piece is a
>>pawn,knight,bishop,rook and queen and the question is if I should try to use
>>pointers to do it shorter or maybe I can trust the compiler to detect that
>>pattern and to do that job.
>>
>>static void addp(int square)
>>{
>> pseudoadd(square);
>> switch (piece(square))
>> {
>> case PAWN:
>> numpiece[square]=numpawns[color(square)];
>> pawns[numpawns[color(square)]][color(square)]=square;
>> numpiece[square]=numpawns[color(square)];
>> numpawns[color(square)]+=1;
>> break;
>> case KNIGHT:
>> numpiece[square]=numknights[color(square)];
>> knights[numknights[color(square)]][color(square)]=square;
>> numpiece[square]=numknights[color(square)];
>> numknights[color(square)]+=1;
>> break;
>> case BISHOP:
>> numpiece[square]=numbishops[color(square)];
>> bishops[numbishops[color(square)]][color(square)]=square;
>> numpiece[square]=numbishops[color(square)];
>> numbishops[color(square)]+=1;
>> break;
>> case ROOK:
>> numpiece[square]=numrooks[color(square)];
>> rooks[numrooks[color(square)]][color(square)]=square;
>> numpiece[square]=numrooks[color(square)];
>> numrooks[color(square)]+=1;
>> break;
>> case QUEEN:
>> numpiece[square]=numqueens[color(square)];
>> queens[numqueens[color(square)]][color(square)]=square;
>> numpiece[square]=numqueens[color(square)];
>> numqueens[color(square)]+=1;
>> break;
>> case KING:
>> kingsquare[color(square)]=square;
>> break;
>> }
>>}
>>
>>Uri
>
>Don't waste any energy optimizing on a setup function.
>
>But I can perhaps give you a suggestion about those numxxxx[] arrays, something
>which I use anyway.
>You can store it all in one unsigned int, use macros to extract what you need.
>The idea is that you don't have to do a lot of conditionals like
>if (piece==QUEEN) x=numqueens[sq], or switch or pointers or whatever,
>instead you replace all that "expensive" stuff with a few shifts:
>x=NUM(piece,color).
>
>Where NUM is a macro to mask out the number, eg.
>#define NUM(p,c) ((counter>>(32*(c)+4*(p))&15)
Thanks for the advice.
I have in my move generator many loops like
for (i=0;i<numpawns[LIGHT];i++)
generatewhitepawnsimple(pawns[i][LIGHT]);
I guess that you suggest to change it to for (i=0;i<NUMWHITE(PAWN);i++) when I
have a global varaible numwhitepieceinfo and I have
#define NUMWHITE(p) ((numwhitepieceinfo>>4*(p))&15)
#define NUMBLACK(p) ((numwhitepieceinfo>>4*(p))&15)
Maybe it can help me to do my perft faster and I do not know but I prefer to
hear advices from other people before trying it.
The question is if >> and & is not slower than array.
If it is not clear thing then I guess that I will not change it because
It is better if I spend more time on improvement of evaluation and search and
not on testing speed options when it is not clear and I only want not to avoid
having something that is obviously slower.
Note that pawns[i][LIGHT] is a sqaure in the board so it may be also possible
to use my 64 bitboard number for white pawns but I do not know if using bitboard
and firstone is faster or slower than using arrays.
For calculating perft it may be slower because for calculating perft I do not
use that bitboard and calculation of the bitboard after every pawn move or pawn
capture may be expensive but for my program I need the bitboard for evaluating
pawn structure so I do not need to calculate it again.
For other pieces I do not have bitboards. so I need to decide if to change my
program
<snipped>
>Of course you can hardwire a few special macros suited to specific pieces or
>color. Also needed are increment and decrement macros, e.g
>
>#define INC(p,c) (counter + (1<<(32*(c)+4*(p))))
I do not use macros for this purpose but
again I may consider to have 2 macros for increasing white and increasing black.
Uri
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.