Author: Russell Reagan
Date: 17:50:36 11/18/02
Go up one level in this thread
On November 18, 2002 at 20:40:20, Pham Hong Nguyen wrote:
>Don't use if - else ;)
So, for example, if I was going to generate pawn moves, it would be better to
have a lookup table of pawn directions for each side and a single function,
rather than to have two seperate functions (GenWhitePawnMoves() and
GenBlackPawnMoves, for example)?
int directions[] = { 8, -8 };
void GenPawnMoves() {
int direction = directions[side_to_move;
// generate moves...
}
So the above would be preferable to somehthing like:
void GenWhitePawnMoves() {
int direction = 8;
// generate moves...
}
void GenBlackPawnMoves() {
int direction = -8;
// generate moves...
}
void GenPawnMoves() {
if (side_to_move == WHITE)
GenWhitePawnMoves();
else
GenBlackPawnMoveS();
}
Is that correct?
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.