r = rank - (side == black) ? 1 : 0; and
r = rank + (side == white? ? 1 : 0;
The result is that rank gets decremented/incremented by 1 irregardless
of the value of side. To fix this, change to the following
r = rank - ((side == black) ? 1 : 0);
r = rank + ((side == white) ? 1 : 0);
Now the code works fine. This change is very important if we were to try
it with the following position.
W: Kh2 Pa3
B: Ka2 Pf3
Without the fix, gnuchess is unable to find the win starting with 1.a4
and instead plays 1. Kg3.
I believe there are certain other places where code like the above is
being employed. In that case, the ?: expression has to be in parentheses.
Kong Sian