in my game of checkers i need to test weather a piece is moving in the right direction. i could write
Code:
bool calculate_move(char board[][ROW_MAX +1][MESSAGE], int current_player, int piece_coordinate_x,
int piece_coordinate_y, int move_coordinate_x, int move_coordinate_y)
{
if (((current_player == PLAYER_WHITE) && (move_coordinate_y - piece_coordinate_y == 1)) || ((current_player == PLAYER_BLACK) && (piece_coordinate_y - move_coordinate_y)))
{
return false;
}
else if ((move_coordinate_y - piece_coordinate_y == 1) && ((move_coordinate_x - piece_coordinate_x == -1) ||
(move_coordinate_x - piece_coordinate_x == 1)))
{
current_player ? move_1_square(board,"b", piece_coordinate_x, piece_coordinate_y, move_coordinate_x,
move_coordinate_y, current_player) : move_1_square(board, "w",piece_coordinate_x,
piece_coordinate_y, move_coordinate_x, move_coordinate_y, current_player);
return true;
}
else
{
// call piece take piece
return true;
}
}
but hat is a real mouthfull
or i could write
Code:
int x;
x = current_player ? (piece_coordinate_y - move_coordinate_y) (move_coordinate_y - piece_coordinate_y)
if (x < 0)
{
return false;
}
else if ((move_coordinate_y - piece_coordinate_y == 1) && ((move_coordinate_x - piece_coordinate_x == -1) ||
(move_coordinate_x - piece_coordinate_x == 1)))
{
current_player ? move_1_square(board,"b", piece_coordinate_x, piece_coordinate_y, move_coordinate_x,
move_coordinate_y, current_player) : move_1_square(board, "w",piece_coordinate_x,
piece_coordinate_y, move_coordinate_x, move_coordinate_y, current_player);
return true;
}
else
{
// call piece take piece
return true;
}
}
but that adds extra lines
can i use an if statement like this
Code:
if ((current_player ? (piece_coordinate_y - move_coordinate_y) : (move_coordinate_y - piece_coordinate_y)) < 0)
{
return false;
}
else if ((move_coordinate_y - piece_coordinate_y == 1) && ((move_coordinate_x - piece_coordinate_x == -1) ||
(move_coordinate_x - piece_coordinate_x == 1)))
{
current_player ? move_1_square(board,"b", piece_coordinate_x, piece_coordinate_y, move_coordinate_x,
move_coordinate_y, current_player) : move_1_square(board, "w",piece_coordinate_x,
piece_coordinate_y, move_coordinate_x, move_coordinate_y, current_player);
return true;
}
else
{
// call piece take piece
return true;
}
}
any advise on which way is best would be appreciated
coop