Author: José Carlos
Date: 08:19:35 12/27/01
Go up one level in this thread
On December 27, 2001 at 10:20:58, Miguel A. Ballicora wrote:
>On December 27, 2001 at 09:02:00, José Carlos wrote:
>
>>
>> When things like these happen, I don't know whether it is the compiler that
>>doesn't work or I'm losing my mind. Yesterday I added this piece of code:
>>
>>for (i=0;i<PosActual->NumPeonesB;i++)
>>{
>> cCol=Columna(g_iPL_PB[i]);
>> cFil=Fila(g_iPL_PB[i]);
>> if (cFil>Retrasado(uPeonesB[cCol]))
>>uPeonesB[cCol]=(ParteAvanzada(uPeonesB[cCol]))|(unsigned int)(cFil);
>> if (cFil<Avanzado(uPeonesB[cCol]))
>>uPeonesB[cCol]=(cFil<<16)|ParteRetrasada(uPeonesB[cCol]);
>>}
>>for (i=0;i<PosActual->NumPeonesN;i++);
>>{
>> cCol=Columna(g_iPL_PN[i]);
>> cFil=Fila(g_iPL_PN[i]);
>> if (cFil<Retrasado(uPeonesN[cCol]))
>>uPeonesN[cCol]=(ParteAvanzada(uPeonesN[cCol]))|(unsigned int)(cFil);
>> if (cFil>Avanzado(uPeonesN[cCol]))
>>uPeonesN[cCol]=(cFil<<16)|ParteRetrasada(uPeonesN[cCol]);
>> i++;
>>}
>>
>> which fills two lists with information for pawn eval. When I run it, then it
>>performed an unhandled exception. I traced it and, to my surprise, when
>>initializing i in the second loop (exactly after executing the second for), the
>>value of i was 8!!!
>
>if PosActual->NumPeonesN is 7, when the first loop finishes i should be 8.
Nope. It is 8 _after_ executing the sencond 'for' with F10.
>I do not see anything wrong with that. The loop breaks when
>i<PosActual->NumPeonesN is no longer true, in other words, 8 or bigger.
>
>> I changed i for other variable; same thing. I tried to loop from
>>PosActual->NumPeonesN-1 down to zero; then i got a very big value instead of 7
>>-there were 8 pawns- (i is an integer).
>
>I'd like to see the actual loop control, if you have
>for (i=PosActual->NumPeonesN-1; i>=0; i--)
>then the loop breaks when i is lower than 0, i.e. -1.
>What kind of integer is i? unsigned? if that is true -1 underflows and goes to
>the maximum positive number that you gan get. The loop will never end and can
>create all sort of troubles that you can imagine.
>The other possibility is that you look at i as unsigned in the debugging session
>giving you a big number.
i is signed int.
>In the second loop there are things that I do not understand:
>
>for (i=0;i<PosActual->NumPeonesN;i++);
> /* ^
> * |
> * I do not think you intended to add this semicolon here!!!!
> */
It is a typo made when removing comments to post it here. Not in my code.
José C.
>{
> cCol=Columna(g_iPL_PN[i]);
> cFil=Fila(g_iPL_PN[i]);
> if (cFil<Retrasado(uPeonesN[cCol]))
> uPeonesN[cCol]=(ParteAvanzada(uPeonesN[cCol]))|(unsigned int)(cFil);
> if (cFil>Avanzado(uPeonesN[cCol]))
> uPeonesN[cCol]=(cFil<<16)|ParteRetrasada(uPeonesN[cCol]);
>
> /* Why you update i here at the end if you do it at the top? */
>
> i++;
>
>}
>
>I hope this helped.
>
>Saludos,
>Miguel
>
>
>> Finally, I had to do a 'while' instead of a 'for' and it worked perfectly.
>> Can anyone tell me if I'm doing something wrong in the above code?
>>
>> Thanks in advance.
>>
>> José C.
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.