summaryrefslogtreecommitdiff
path: root/lib/print.c
blob: 431641eebdc7599411b3215d8d4d5b6eaa16cd0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>

#include "print.h"
#include "piece.h"

/* Printing related functions */
void print_piece(Piece p) {
    putchar(piece_character(p));
}

void print_square(Square s) {
    puts("+-+\n|");

    if (s.piece == NULL)
        switch (s.color) {
        case WHITE:
            putchar(' ');
            break;;
        case BLACK:
            putchar('/');
            break;
        default:
            perror("Wait... what?\n");
            exit(EXIT_FAILURE);
        }
    else
        print_piece(*s.piece);

    puts("|\n+-+");

    return;
}

void print_board(Board *b) {
    int i, j;

    for (i = 0; i < SIZE; i++) {
        for (j = 0; j < SIZE; j++) {
            print_square(*b[i][j]);
        }

        putchar('\n');
    }
}
nihil fit ex nihilo