From 5209362ab2750744d516043e616134fca40e4a5f Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Fri, 28 Apr 2006 15:31:45 -0400 Subject: [PATCH] libchess: A few cleanups. Increased MAX_PGN_NAG from 5 to 8. This could be dynamic and may be later on. --- libchess/chess.h | 29 ++++++++++++----------------- libchess/pgn.c | 4 ++-- src/cboard.c | 26 +++++++++++++------------- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/libchess/chess.h b/libchess/chess.h index f427795..31a56e2 100644 --- a/libchess/chess.h +++ b/libchess/chess.h @@ -22,18 +22,14 @@ #define PGN_TIME_FORMAT "%Y.%m.%d" #define MAX_PGN_LINE_LEN 255 #define MAX_SAN_MOVE_LEN 7 -#define MAX_PGN_NAG 5 +#define MAX_PGN_NAG 8 #define VALIDRANK VALIDFILE #define VALIDFILE(f) (f >= 1 && f <= 8) -#define RANKTOBOARD ROWTOBOARD -#define FILETOBOARD COLTOBOARD -#define RANKTOINT ROWTOINT -#define FILETOINT COLTOINT -#define ROWTOBOARD(r) (8 - r) -#define COLTOBOARD(c) (c - 1) -#define ROWTOINT(r) (r - '0') -#define COLTOINT(c) (c - ('a' - 1)) +#define RANKTOBOARD(r) (8 - r) +#define FILETOBOARD(c) (c - 1) +#define RANKTOINT(r) (r - '0') +#define FILETOINT(c) (c - ('a' - 1)) #define VALIDROW(r) (r >= '1' && r <= '8') #define VALIDCOL(c) (c >= 'a' && c <= 'h') #define INTTORANK(r) (r + '0') @@ -45,7 +41,7 @@ #define TEST_FLAG(var, f) (var & f) enum { - OPEN_SQUARE, PAWN, BISHOP, ROOK, KNIGHT, QUEEN, KING, MAX_PIECES + OPEN_SQUARE, PAWN, BISHOP, ROOK, KNIGHT, QUEEN, KING }; enum { @@ -59,8 +55,8 @@ enum { #define GF_WK_CASTLE 0x08 #define GF_WQ_CASTLE 0x010 #define GF_BK_CASTLE 0x020 -#define GF_BQ_CASTLE 0x0400 -#define GF_BLACK_OPENING 0x0800 +#define GF_BQ_CASTLE 0x040 +#define GF_BLACK_OPENING 0x080 /* * The chess board. @@ -90,7 +86,7 @@ typedef struct tags { typedef struct history { char *move; // The SAN move text. char *comment; // Annotation for this move. - unsigned char nag[MAX_PGN_NAG]; // Numeric Annotation Glyph. FIXME + unsigned char nag[MAX_PGN_NAG]; // Numeric Annotation Glyph. struct history **rav; // Variation of the current move. } HISTORY; @@ -376,8 +372,8 @@ void pgn_reset_enpassant(BOARD b); void pgn_reset_valid_moves(BOARD b); /* - * Sets valid moves from game 'g' using board 'b'. The valid moves are for the - * piece on the board 'b' at 'rank' and 'file'. Returns nothing. + * Sets valid moves (b.valid) from game 'g' using board 'b'. The valid moves + * are for the piece on the board 'b' at 'rank' and 'file'. Returns nothing. */ void pgn_find_valid_moves(GAME g, BOARD b, int rank, int file); @@ -394,8 +390,7 @@ typedef enum { E_PGN_OK, E_PGN_PARSE, E_PGN_AMBIGUOUS, - E_PGN_INVALID, - E_MAX_PGN_ERRORS + E_PGN_INVALID } pgn_error; #endif diff --git a/libchess/pgn.c b/libchess/pgn.c index 7fe66a0..5f8f8ea 100644 --- a/libchess/pgn.c +++ b/libchess/pgn.c @@ -1203,11 +1203,11 @@ static int parse_fen_line(BOARD b, unsigned *flags, char *turn, char *ply, return E_PGN_PARSE; for (; n; --n, col++) - b[ROWTOBOARD(row)][COLTOBOARD(col)].icon = + b[RANKTOBOARD(row)][FILETOBOARD(col)].icon = pgn_int_to_piece(WHITE, OPEN_SQUARE); } else if (pgn_piece_to_int(*tmp) != -1) - b[ROWTOBOARD(row)][COLTOBOARD(col++)].icon = *tmp; + b[RANKTOBOARD(row)][FILETOBOARD(col++)].icon = *tmp; else return E_PGN_PARSE; diff --git a/src/cboard.c b/src/cboard.c index 8afc975..bc24c25 100644 --- a/src/cboard.c +++ b/src/cboard.c @@ -138,8 +138,8 @@ void update_cursor(GAME g, int idx) while (!isdigit(*p)) p--; - d->c_row = ROWTOINT(*p--); - d->c_col = COLTOINT(*p); + d->c_row = RANKTOINT(*p--); + d->c_col = FILETOINT(*p); } static int init_nag() @@ -1614,7 +1614,7 @@ static char *board_to_san(GAME *g, BOARD b) d->sp.srow, x_grid_chars[d->sp.col - 1], d->sp.row); p = str; - piece = pgn_piece_to_int(b[ROWTOBOARD(d->sp.srow)][COLTOBOARD(d->sp.scol)].icon); + piece = pgn_piece_to_int(b[RANKTOBOARD(d->sp.srow)][FILETOBOARD(d->sp.scol)].icon); if (piece == PAWN && ((d->sp.row == 8 && g->turn == WHITE) || (d->sp.row == 1 && g->turn == BLACK))) { @@ -2642,9 +2642,9 @@ static int playmode_keys(chtype c) d->sp.col = d->c_col; if (editmode) { - p = d->b[ROWTOBOARD(d->sp.srow)][COLTOBOARD(d->sp.scol)].icon; - d->b[ROWTOBOARD(d->sp.row)][COLTOBOARD(d->sp.col)].icon = p; - d->b[ROWTOBOARD(d->sp.srow)][COLTOBOARD(d->sp.scol)].icon = + p = d->b[RANKTOBOARD(d->sp.srow)][FILETOBOARD(d->sp.scol)].icon; + d->b[RANKTOBOARD(d->sp.row)][FILETOBOARD(d->sp.col)].icon = p; + d->b[RANKTOBOARD(d->sp.srow)][FILETOBOARD(d->sp.scol)].icon = pgn_int_to_piece(game[gindex].turn, OPEN_SQUARE); d->sp.icon = d->sp.srow = d->sp.scol = 0; break; @@ -2816,10 +2816,10 @@ static void editmode_keys(chtype c) break; case 'd': if (d->sp.icon) - d->b[ROWTOBOARD(d->sp.srow)][COLTOBOARD(d->sp.scol)].icon = + d->b[RANKTOBOARD(d->sp.srow)][FILETOBOARD(d->sp.scol)].icon = pgn_int_to_piece(game[gindex].turn, OPEN_SQUARE); else - d->b[ROWTOBOARD(d->c_row)][COLTOBOARD(d->c_col)].icon = + d->b[RANKTOBOARD(d->c_row)][FILETOBOARD(d->c_col)].icon = pgn_int_to_piece(game[gindex].turn, OPEN_SQUARE); d->sp.icon = d->sp.srow = d->sp.scol = 0; @@ -2829,9 +2829,9 @@ static void editmode_keys(chtype c) update_all(game[gindex]); break; case 'c': - castling_state(&game[gindex], d->b, ROWTOBOARD(d->c_row), - COLTOBOARD(d->c_col), - d->b[ROWTOBOARD(d->c_row)][COLTOBOARD(d->c_col)].icon, 1); + castling_state(&game[gindex], d->b, RANKTOBOARD(d->c_row), + FILETOBOARD(d->c_col), + d->b[RANKTOBOARD(d->c_row)][FILETOBOARD(d->c_col)].icon, 1); break; case 'i': c = message(GAME_EDIT_TITLE, GAME_EDIT_PROMPT, "%s", @@ -2840,12 +2840,12 @@ static void editmode_keys(chtype c) if (pgn_piece_to_int(c) == -1) break; - d->b[ROWTOBOARD(d->c_row)][COLTOBOARD(d->c_col)].icon = c; + d->b[RANKTOBOARD(d->c_row)][FILETOBOARD(d->c_col)].icon = c; break; case 'p': if (d->c_row == 6 || d->c_row == 3) { pgn_reset_enpassant(d->b); - d->b[ROWTOBOARD(d->c_row)][COLTOBOARD(d->c_col)].enpassant = 1; + d->b[RANKTOBOARD(d->c_row)][FILETOBOARD(d->c_col)].enpassant = 1; } break; default: -- 2.11.4.GIT