chess/text_renderer
This module provides basic functionality to render a game state to a String.
This module does not provide a user facing UI or even any user interaction. It’s merely used for testing/debugging purposes.
However, feel free to use the provided functions in here to experiment with this library before building your own UI experience.
Example starting position:
White's turn
┌─────────────────┐
8 │ ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ │
7 │ ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ │
6 │ · · · · · · · · │
5 │ · · · · · · · · │
4 │ · · · · · · · · │
3 │ · · · · · · · · │
2 │ ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ │
1 │ ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ │
└─────────────────┘
a b c d e f g h
🐞 This example will appear be misaligned, if it’s not rendered with a monospace font.
Values
pub fn render(game game: chess.GameState) -> String
Renders the game
into a String without using any ANSI codes.
See the module description for an example.
Use render_with_moves
if you want to highlight available moves as well.
pub fn render_with_moves(
game game: chess.GameState,
selected_figure selected_figure: chess.Coordinate,
moves moves: set.Set(chess.AvailableMove),
) -> String
Like render
but also highlights a set of available moves on the board through ANSI codes.
selected_figure
will be colored yellow- standard moves will have a yellow background
- pawn promotion moves will have a blue background
- en passant moves will have a yellow background
- Long/Short castling will have a yellow background at the king’s destination square
- squares of multiple different moves have a red background to signalize an error
Do not use this if you don’t want ANSI codes in the output string.