summaryrefslogtreecommitdiff
path: root/lib/board.c
blob: 3eb76035decbdb4090088fc63448bb9a89a830ce (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdlib.h>
#include <stdio.h>

#include "board.h"

Board _setup_colors(Board b) {
    int i, j;
    
    for (i = 0; i < SIZE; i++)
        for (j = 0; j < SIZE; j++)
            if (i % 2) // Odd rows start with white
                if (j % 2)
                    b[i][j].color = WHITE;
                else
                    b[i][j].color = BLACK;
            else
                if (j % 2)
                    b[i][j].color = BLACK;
                else
                    b[i][j].color = WHITE;

    return b;
}

Board _pawns(Board b) {
    return b;
}

Board _rocks(Board b) {
    return b;
}

Board _knights(Board b) {
    return b;
}

Board _bishops(Board b) {
    return b;
}

Board _queens(Board b) {
    return b;
}

Board _kings(Board b) {
    return b;
}

Board _setup_pieces(Board b) {
    return _pawns(_rocks(_knights(_bishops(_queens(_kings(b)))))); // :-)
}

Board _initial_setup(Board b) {
    return _setup_pieces(_setup_colors(b));
}

Board board_init() {
    int i, j;

    Board b = malloc(sizeof(Square*) * SIZE);
    
    for (i = 0; i < SIZE; i++) {
        b[i] = malloc(sizeof(Square) * SIZE);
        for (j = 0; j < SIZE; j++)
            b[i][j].piece = NULL;
    }

    return _initial_setup(b);
}

int board_delete(Board* b) {
    int i;

    for (i = 0; i < SIZE; i++)
        free(b[i]);

    free(b);

    return 0;
}
nihil fit ex nihilo