Skip to content

Commit

Permalink
Teach file_to_char() about upper/lower case
Browse files Browse the repository at this point in the history
This allows to further simplify Position::fen()

No functional change.
  • Loading branch information
mcostalba committed Jan 4, 2013
1 parent 9d11515 commit 900e2d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/position.cpp
Expand Up @@ -358,16 +358,16 @@ const string Position::fen() const {
ss << (sideToMove == WHITE ? " w " : " b ");

if (can_castle(WHITE_OO))
ss << (chess960 ? char(toupper(file_to_char(file_of(castle_rook_square(WHITE, KING_SIDE))))) : 'K');
ss << (chess960 ? file_to_char(file_of(castle_rook_square(WHITE, KING_SIDE)), false) : 'K');

if (can_castle(WHITE_OOO))
ss << (chess960 ? char(toupper(file_to_char(file_of(castle_rook_square(WHITE, QUEEN_SIDE))))) : 'Q');
ss << (chess960 ? file_to_char(file_of(castle_rook_square(WHITE, QUEEN_SIDE)), false) : 'Q');

if (can_castle(BLACK_OO))
ss << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK, KING_SIDE))) : 'k');
ss << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK, KING_SIDE)), true) : 'k');

if (can_castle(BLACK_OOO))
ss << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK, QUEEN_SIDE))) : 'q');
ss << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK, QUEEN_SIDE)), true) : 'q');

if (st->castleRights == CASTLES_NONE)
ss << '-';
Expand Down
4 changes: 2 additions & 2 deletions src/types.h
Expand Up @@ -441,8 +441,8 @@ inline int square_distance(Square s1, Square s2) {
return SquareDistance[s1][s2];
}

inline char file_to_char(File f) {
return char(f - FILE_A + 'a');
inline char file_to_char(File f, bool tolower = true) {
return char(f - FILE_A + (tolower ? 'a' : 'A'));
}

inline char rank_to_char(Rank r) {
Expand Down

0 comments on commit 900e2d4

Please sign in to comment.