Author: Uri Blass
Date: 19:08:54 04/16/03
Go up one level in this thread
On April 16, 2003 at 16:08:05, Bruce Moreland wrote:
>On April 16, 2003 at 05:34:02, Uri Blass wrote:
>
>>better to give only part of the chars that are used in the function?
>>
>>The problem is that my makemove get a struct of 4 chars
>>with details about the move(maybe it is better to use one integer and to get rid
>>of the 4 chars but I decided that it is a big change that I do not like to do
>>now).
>>
>>I call from makemove to functions that get part of the chars
>>for example
>>
>>updateblackpiece(m.from,m.to);
>>
>>The question is if it is better to call only m and not the 2 varaibles
>>m.to and m.from
>>
>>
>>there is already a union that include these numbers so I assume
>>that they they are in memory.
>>
>>I also plan to write a function that update some varaibles and
>>I need only m.from,m.to,m.bits and I do not need m.promote and
>>the question is if using m is better than using 3 of the
>>4 varaibles.
>>
>>Another solution is to have a global structure of 4 chars for the move that
>>the program consider and to update it every time that I make a move in the
>>beginning of makemove so I do not need to give parameters to the functions
>>that movei call.
>>
>>Note that my undomove does not get a move as a varaible and
>>I start it by
>>
>>move_bytes m=hist_dat[hply-1].m.b;
>>
>>I update
>>hist_dat[hply].m.b in my make move but it is clear that it is not
>>a good idea to use this global array to get the numbers and maybe it is better
>>to have m as global varaible so I can use it in every function.
>>
>>
>>What is the best solution?
>>
>>I do not see difference in readibility if I give m to a function
>>or give 2 chars to the same function and I want to know a clear rule what is
>>faster not by try and error.
>>
>>Uri
>
>You gotta test it. You are probably sign-extending all over the place, which
>used to be very nasty-bad, and still might be, but on the other hand, you have a
>little less memory bandwidth.
>
>If you are serious, you will try it both ways. Be a man.
>
>bruce
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
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.