Author: David Dory
Date: 14:34:34 01/25/04
Go up one level in this thread
On January 25, 2004 at 08:30:05, Eiko Bleicher wrote:
>Hello Dave,
>
>does this only work with variable named that way? Could you provide a complete
>code snippet that produces some strange behaviour? I'll try to find out then.
>
>Eiko
Hi Eiko,
Yes, as soon as I changed the variable name from "tr" to "rt", the problem was
solved. I just couldn't accept that fact, thought maybe it was the debugger
only, (wrong!), then thought maybe restarting the program would correct it (also
wrong!), then thought maybe restarting the whole computer would correct it
(again wrong!!)
As I'm working quite a bit on my programs code, I can't make the function
reproduce that error, but the key may be that the function had the final
return(True) statement commented out, in error.
So I kept getting a warning of "not every branch in function InCheck returns a
value", which I was ignoring while I fried bigger fish of code.
I tried to re-create it, but it was not having any of it. I STILL don't trust
int variables named "tr" however. It was by far the most bizarre thing I've seen
in an IDE before.
The code was in InCheck(), and was similar to this below. Except on the exact
line, I've changed the "tr" to "rt", however:
int InCheck(int r, int c) {
//r == row of king, and , c == column of king being checked by InCheck()
//Uses the "super chess piece" idea
//besides telling whether any move puts (or would put) the king in check,
//this sub could be called repeatedly, "as if" the king were on the back row
squares between itself
//and the rook it is looking to castle toward. If these squares are being
attacked by the other
// side, (or not), we'd know if this castle move was illegal or legal.
int rt, ct, pl; //pl is short for player
int i = 1;
rt = r; ct = c;
pl = player;
//the pl * # code for pawns just switches the code to match with the player
of either color
//needed because pawns for white attack upward, but black pawns only attack
downward.
//All other pieces are vectorless, and only need pl * the piece we're
looking for to work
//for either player
//left to right possible checks by pawn, covers either black or white player
if(board[r + pl * 1][c - pl * 1] == (pl * BP) || board[r + pl * 1][c + pl *
1] == (pl * BP)) return(False);
// check for Knights //clockwise from 12 o'clock
if(board[r + 2][c + 1] == (pl * BN) || board[r + 1][c + 2] == (pl * BN))
return(False); //1-2
if(board[r - 1][c - 2] == (pl * BN) || board[r - 2][c + 1] == (pl * BN))
return(False); //4-5
if(board[r - 2][c - 1] == (pl * BN) || board[r - 1][c - 2] == (pl * BN))
return(False); //7-8
if(board[r + 1][c - 2] == (pl * BN) || board[r + 2][c - 1] == (pl * BN))
return(False); //10-11
//tr = r; don't EVER use "tr" for an int variable. It won't always assign OR
decrement, right!!
//check for Bishops & Queens - clockwise from 12 o'clock
//Note the while statements may be ONE line only and end with a semi-colon
rt = r; ct = c;
while(board[++rt][++ct] == 0); //the #1 bishop's ray, at 2 o'clock
if(board[rt][ct] == (pl * BB) || board[rt][ct] == (pl * BQ)) return(False);
//return(False) = in check
// 888888888888888888888888888888888888888888888888888888888888888888
tr = r; tc = c; // ** This is the line that fried VC 6's brain. It made tr
into a r + 1 **
while(board[--tr][++ct] == 0); //the #2 bishop's ray, at 4 o'clock
// ** and instead of decrimenting tr in the line above, it would increment
it by one!
//88888888888888888888888888888888888888888888888888888888888888888888
if(board[rt][ct] == (pl * BB) || board[rt][ct] == (pl * BQ)) return(False);
... rest of the function followed.
Dave
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.