Author: Uri Blass
Date: 03:08:54 08/21/03
Go up one level in this thread
On August 21, 2003 at 05:40:41, Daniel Clausen wrote: >On August 21, 2003 at 05:16:17, Uri Blass wrote: > >[snip] > > >>I payed attention to the fact that b and c can never happen if a does not >>happen so I cahnge it to >>if a >>{ >>... >> if b >> { >>... >> } >> if c >> { >>... >> } >>} > >If b and c can only happen in case a happens, I definitely would write it like >that. (as opposed to the flattened version) But not because of a potential speed >gain but because it's most likely also clearer to read. (at least for me) > >Three if-statements in a row are independant in my understanding. If they're >not, I would replace them with a switch/case, make use of 'else if' instead of >normal ifs or nest them as in your example. Which one of the 3 possibilities of >course depends on the concrete case. > >Did you measure how much speed you gained in your case? And where approx are >these if-statements? (if they're not in eval, I can't image you would notice >_any_ speed difference) > >Sargon The if were in updating arrays in my makemove. The speed improvement was small(I think less than 1% speed improvement but I could see the program run faster) Note that I added more arrays to update incrementally in my makemove. In the relevant case I start with i=infodirections[sq] because I do not like to call infodirection[sq] again and again; i is a number that tells me the direction that a king in square sq can goto(in case that the board is empty) for example when sq=0 there are only 3 directions that it can go so only 3 bits are 1. The if are about directions and the point is that if one direction is impossible I know that other 2 directions are also impossible. If the king cannot go backward than the king cannot go backward in diagnol direction. The result is that instead if (i&1) { ... } if (i&2) { ... } if (i&4) { ... } I have if (i&1) { ... if (i&16) { ..... } if (i&64) { ... } } Note that it may be also better to get rid of the magic numbers and use if (i&kingup) { ... if (i&kingleftup) { .... } if (i&kingrightup) { ... } } 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.