Thanks all for your answers. They were very informative.Dann Corbit wrote:Unless it is in a very time critical place, just write which is the most clear to you. On some compilers one technique will be faster than another, but it can change even with different compiler settings.michiguel wrote:They are supposed to be slower. However, in certain situations the alternative is to have a switch or a chain of "if else" that involves lots of branches. When would you choose one approach over the other?
I know I have to try, but having an educated guess at the beginning helps a lot.
Miguel
[snip]
I a just rewrote my move ordering data structure and I am using pointer to functions. I do not believe it is in a critical spot, because the function itself spends quite a bit of time in generating and ordering the moves.
The idea is that now I can experiment with different schemes in a much easier way. In each position I initialize an array of pointer to functions that will generate and sort moves in phases (job done in function call pool_init()). A crude example is Function[0] generates and order captures, Function[1] pick killers from the table, Function[2] generates non-captures. Every time I have to pick a move (pool_pick()), I loop through the moves available and when I run out, I call the next function to generate moves from the next phase. When I run out moves and functions, I am done (pool_done()). So, in case of quiescence, I can initialize
Function[0]=load_captures;
Function[1]=NULL;
But if I want to generate checks in the first ply of quiescence(), I do
Function[0]=load_captures;
Function[1]=load_checks;
Function[2]=NULL;
The rest of the code remains intact. To do this, I need a switch at the begining of pool_init()
The concept is that I want to experiment with different ordering schemes that depend on the position (why endgames should have move ordering different from middle games?). But I am digressing...
Anyway, I was always curious about the efficiency. For instance, everytime I evaluate a piece (mobility, positions etc) I call a pointer to a function that deals with a specific piece. I am not sure if this efficient, but I cleaned up my code very much!! I need to test it thoroughly, but I am wiling to sacrifice a little bit of speed for clarity.
Thanks again,
Miguel