Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: a question about the advantage of short code for tasks that are done

Author: Robert Hyatt

Date: 08:44:05 04/11/03

Go up one level in this thread


On April 11, 2003 at 11:09:47, Uri Blass wrote:

>only one time or not done often.

Any good software engineering book would recommend that you go for readability.
IE
design it to make it easy to understand, easy to modify, when the code is not
time-
critical.



>
>I have task that I do only one time and I may do my code shorter
>by adding functions.
>
>Note that they are a small minority of the code so
>I do not expect a big reduction.
>
>Here are some examples:
>
>1)In the code that build the array of knightmoves I have
>8 similiar if.
>
>if (fil>=2&&rank>=1)
>		{
>			knightmove[sq][i]=index(fil-2,rank-1);
>			direction[sq][knightmove[sq][i]]=dknight;
>			i++;
>		}
>
>Is there an advantage in changing it to something like
>
>if (fil>=2&&rank>=1)
>{
>buildknightarrays(sq,i,fil-2,rank-1);
>i++;
>}
>
>or maybe it is even better to give buildknightarrays
>a pointer to i to save the i++ that I do 8 times.
>
>
>2)In my code for setup position I have the following code
>
>	case 'n':
>				info[square]+=KNIGHT;
>				valuepieces+=3;
>				if (color(square)==LIGHT)
>					valpieces[0]+=3;
>				else
>					valpieces[1]+=3;
>				break;
>
>I can replace 3 by piece_value[KNIGHT]
>replace 0 by LIGHT and replace 1 by DARK
>
>I can also have a function
>putpiece(int square,int piece)
>{
>info[square]+=piece;
>valuepieces+=valpieces[piece];
>if (color(square)=LIGHT)
>  valpieces[LIGHT]+=valpieces[piece];
>else
> valpieces[DARK]+=valpieces[piece];
>}
>
>Questions:
>
>
>1)Is there an advantage for doing these things except doing the code more easy
>to read?
>
>2)Is it better to add a special file to the project of things that I do
>not do often(like initializing arrays every time that I setup a new FEN)?
>
>I remember a claim of christhope that he tried to limit the
>things that the program does often to 64k or 128k(I am not sure about the
>number) but I have no idea how much memory movei use for the main things that
>it does.
>
>The main things that it does include the move generator
>and the search but both things are done in different files in the project.
>
>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.