printf ("Type engine"); gets(player);
if ((process_pgn_file())!=0) { all done }
if (strcmp(player,white)==0) engine=0; // decide the color
if (strcmp(player,black)==0) engine=1;
// Processing the moves
for (x=0; x<=MAX_MOVES; x++) {
if (x&1 != engine) continue;
do_something_with_the_move_of_player();
}
So what was wrong?
90% of coding is debugging, the other 10% is writing bugs.
Well, a few of things look like potential issues.
A) the "player" might not match either one for the current game being processed.
B) MAX_MOVES looks like a constant, and not the number of moves in the current game.
C) Loop depends on how move numbers are counted (full moves v half moves).
aside from what has been mentioned already, C operator precedence:
& has lower priority than != (I never understood why bitwise ops are lower than relational to be honest),
so the expression evaluates as x & (1 != engine) instead of the intended (x & 1) != engine
or maybe it was intended?
mar wrote: ↑Sun Jan 06, 2019 6:41 pm
aside from what has been mentioned already,
These were deliberately left out in the pseudo code but are covered in the real code, so those are not the issue.
mar wrote: ↑Sun Jan 06, 2019 6:41 pmC operator precedence:
& has lower priority than != (I never understood why bitwise ops are lower than relational to be honest),
so the expression evaluates as x & (1 != engine) instead of the intended (x & 1) != engine
or maybe it was intended?
Just to make it clear for all those who are not fully aware of the consequences of this bug: the expression "x & (1 != engine)" is evaluated differently from the intended "(x & 1) != engine" if engine=1 and x is an even number (including x=0). In all three other combinations it "works by accident".
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)