diff options
author | Raúl Benencia <rul@kalgan.cc> | 2015-03-27 11:19:16 -0300 |
---|---|---|
committer | Raúl Benencia <rul@kalgan.cc> | 2015-03-27 11:19:16 -0300 |
commit | e7497d2dde46b8fae5493c127f4dc33307a65da5 (patch) | |
tree | 4f60b18a3cf917b201f627bc448debafcf04a38b /lib/board.c |
initial commit
Diffstat (limited to 'lib/board.c')
-rw-r--r-- | lib/board.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/lib/board.c b/lib/board.c new file mode 100644 index 0000000..6543bcc --- /dev/null +++ b/lib/board.c @@ -0,0 +1,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 b; +} + +int board_delete(Board* b) { + int i; + + for (i = 0; i < SIZE; i++) + free(b[i]); + + free(b); + + return 0; +} |