#include #include #include "print.h" #include "board.h" #include "coordinate.h" #include "piece.h" static void _print_row_separator() { int j; for (j = 0; j < SIZE; j++) printf("+---"); printf("+\n"); } static Coord _next_coord(Coord c, Color side) { if (side == WHITE) return coord_next(c); else return coord_prev(c); } /* Printing related functions */ void print_piece(Piece p) { putchar(piece_character(p)); } void print_square(Square s) { if (s.piece == NULL) if (s.color == WHITE) putchar(' '); else putchar('/'); else print_piece(*s.piece); } /* * Pretty print the board. The "side" parameter lets you choose the * orientation. Use WHITE for a white player perspective, BLACK otherwise. */ void print_board(Board b, Color side) { Coord c = _next_coord(coord_null(), side); char current_row = coord_get_row(c); _print_row_separator(); while (!coord_is_null(c)) { // Print the square printf("| "); print_square(board_get_square(b, c)); putchar(' '); // Shall we move forward or backwards? c = _next_coord(c, side); // If the row changed then we must start a new line if (coord_get_row(c) != current_row) { printf("|\n"); _print_row_separator(); current_row = coord_get_row(c); } } }