Skip to content

Commit

Permalink
Fixed castling bug and edited position settings
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericojordan committed Jul 6, 2017
1 parent e538b29 commit 3e2f113
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/fast-chess-gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,11 @@ void handleEvent(SDL_Event event, Game * game, char * color, BOOL * hasAI, int *
if (*editing) {
*lastMove = 0;
} else {
game->position.epSquare = -1;
game->position.castlingRights = CASTLE_KINGSIDE_WHITE|CASTLE_QUEENSIDE_WHITE|CASTLE_KINGSIDE_BLACK|CASTLE_QUEENSIDE_BLACK;
game->position.halfmoveClock = 0;
game->position.fullmoveNumber = 1;

char fen[MAX_FEN_LEN];
toFen(fen, &(game->position));
getFenGame(game, fen);
Expand Down
8 changes: 8 additions & 0 deletions src/fast-chess.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,10 @@ BOOL canCastleKingside(Position * position, char color) {

case WHITE:
if ( (position->castlingRights&CASTLE_KINGSIDE_WHITE) &&
(position->board[str2index("e1")] == WHITE|KING) &&
(position->board[str2index("f1")] == EMPTY) &&
(position->board[str2index("g1")] == EMPTY) &&
(position->board[str2index("h1")] == WHITE|ROOK) &&
(!isAttacked(str2bb("e1"), position->board, opponent(color))) &&
(!isAttacked(str2bb("f1"), position->board, opponent(color))) &&
(!isAttacked(str2bb("g1"), position->board, opponent(color))) )
Expand All @@ -1269,8 +1271,10 @@ BOOL canCastleKingside(Position * position, char color) {

case BLACK:
if ( (position->castlingRights&CASTLE_KINGSIDE_BLACK) &&
(position->board[str2index("e8")] == BLACK|KING) &&
(position->board[str2index("f8")] == EMPTY) &&
(position->board[str2index("g8")] == EMPTY) &&
(position->board[str2index("h8")] == BLACK|ROOK) &&
(!isAttacked(str2bb("e8"), position->board, opponent(color))) &&
(!isAttacked(str2bb("f8"), position->board, opponent(color))) &&
(!isAttacked(str2bb("g8"), position->board, opponent(color))) )
Expand All @@ -1287,9 +1291,11 @@ BOOL canCastleQueenside(Position * position, char color) {

case WHITE:
if ( (position->castlingRights&CASTLE_QUEENSIDE_WHITE) &&
(position->board[str2index("a1")] == WHITE|ROOK) &&
(position->board[str2index("b1")] == EMPTY) &&
(position->board[str2index("c1")] == EMPTY) &&
(position->board[str2index("d1")] == EMPTY) &&
(position->board[str2index("e1")] == WHITE|KING) &&
(!isAttacked(str2bb("c1"), position->board, opponent(color))) &&
(!isAttacked(str2bb("d1"), position->board, opponent(color))) &&
(!isAttacked(str2bb("e1"), position->board, opponent(color))) )
Expand All @@ -1299,9 +1305,11 @@ BOOL canCastleQueenside(Position * position, char color) {

case BLACK:
if ( (position->castlingRights&CASTLE_QUEENSIDE_BLACK) &&
(position->board[str2index("a8")] == BLACK|ROOK) &&
(position->board[str2index("b8")] == EMPTY) &&
(position->board[str2index("c8")] == EMPTY) &&
(position->board[str2index("d8")] == EMPTY) &&
(position->board[str2index("e8")] == BLACK|KING) &&
(!isAttacked(str2bb("c8"), position->board, opponent(color))) &&
(!isAttacked(str2bb("d8"), position->board, opponent(color))) &&
(!isAttacked(str2bb("e8"), position->board, opponent(color))) )
Expand Down

0 comments on commit 3e2f113

Please sign in to comment.