Tue, 21 Apr 2026 22:22:02 +0200
correctly use unicode chars for white pieces
this might look worse on some terminals but enables
support for terminals which use colored emojis
resolves #827
| src/chess/rules.c | file | annotate | diff | comparison | revisions | |
| src/game.c | file | annotate | diff | comparison | revisions |
--- a/src/chess/rules.c Mon Apr 20 22:01:38 2026 +0200 +++ b/src/chess/rules.c Tue Apr 21 22:22:02 2026 +0200 @@ -192,14 +192,26 @@ } char* getpieceunicode(uint8_t piece) { - switch (piece & PIECE_MASK) { - case PAWN: return "\u265f"; - case ROOK: return "\u265c"; - case KNIGHT: return "\u265e"; - case BISHOP: return "\u265d"; - case QUEEN: return "\u265b"; - case KING: return "\u265a"; - default: return ""; + if ((piece & COLOR_MASK) == WHITE) { + switch (piece & PIECE_MASK) { + case PAWN: return "\u2659"; + case ROOK: return "\u2656"; + case KNIGHT: return "\u2658"; + case BISHOP: return "\u2657"; + case QUEEN: return "\u2655"; + case KING: return "\u2654"; + default: return ""; + } + } else { + switch (piece & PIECE_MASK) { + case PAWN: return "\u265f"; + case ROOK: return "\u265c"; + case KNIGHT: return "\u265e"; + case BISHOP: return "\u265d"; + case QUEEN: return "\u265b"; + case KING: return "\u265a"; + default: return ""; + } } }
--- a/src/game.c Mon Apr 20 22:01:38 2026 +0200 +++ b/src/game.c Tue Apr 21 22:22:02 2026 +0200 @@ -82,14 +82,15 @@ for (uint8_t y = 0 ; y < 8 ; y++) { for (uint8_t x = 0 ; x < 8 ; x++) { uint8_t col = gamestate->board[y][x] & COLOR_MASK; - uint8_t piece = gamestate->board[y][x] & PIECE_MASK; + uint8_t piece = gamestate->board[y][x]; char piecestr[5]; if (piece) { if (unicode) { char* uc = getpieceunicode(piece); strncpy(piecestr, uc, 5); } else { - piecestr[0] = piece == PAWN ? 'P' : getpiecechr(piece); + piecestr[0] = (piece & PIECE_MASK) == PAWN + ? 'P' : getpiecechr(piece); piecestr[1] = '\0'; } } else {