Author: David Dory
Date: 14:33:43 04/15/03
Go up one level in this thread
On April 15, 2003 at 13:53:56, Uri Blass wrote:
>I think about making 2 function of making moves(one for white and one for black.
>The point is that there are a lot of cases when I use the varaible side in
>makemove and it may be faster not to use it and to have a different code for
>white and black(I already has code for white and black in big part of my
>functions to generate moves but I also have not one code for generate white move
>and one code for generate black moves).
>
>The question is if it is a good idea because adding functions is going to make
>my program longer(it is already a big code because of many functions).
>
>My question is if there is a demage in speed from making the code bigger and
>if there is a way to predict it without testing.
>
>I found that there was some improvement in speed from replacing 2 of my
>functions by 4 functions(2 for white and 2 for black) but when I continue in
>this way the code becomes slower.
>
>I also suspect that a possible reason for lack of improvement is that without
>more functions the compiler is better in detecting patterns and the compiler may
>prefer seeing 2 times a slow thing and not one time slightly faster things.
>
>A possible explanation may be of course some random compiler optimization but
>when I see the code being slower again and again then I suspect that it is not
>the case.
>
>I think that I will leave it and add a special function to calculate some new
>varaibles and arrays that are going to be used in the evaluation.
>
>The varaibles that need to be updated may be different when it is black to move
>or white to move so again I may consider to have 2 functions.
>
>What is your opinion?
>
>Uri
I vote for one function. Principle reason is conciseness and readibility, but I
see no reason you should suffer a slowdown from using one function only.
If you organize the MakeMove function (let's say the color variable is a
parameter to the function).
So in one (and only one) section you have all the variables used by just one
color. In one statement, all the color specific code is included:
if(player == WHITE) {
//all the code for white only goes here
}
else {
//all the code for black only goes here
}
I was reminded recently that great programming code is killed "dead", by highly
optimized good program code. That is, the "good" is death to the "great" in
programming. So get your logic coded up the very best that you can, and save the
optimizations, which tend to make the program much harder to read and edit
without introducing errors, for last.
For a good example, just read "One Jump Ahead" by J. Schaeffer. You feel like
reaching into the book's pages and slapping Schaeffer's hands away from the
keyboard. So many times he just HAD to do ONE MORE tweak - and wound up
introducing a bug into Chinook. Naturally it would all come back to bite him
badly in a critical game and match.
Good luck!
Dave
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.