From 56afe8c36ec3ec84f3e34e658b2890a3e0479eee Mon Sep 17 00:00:00 2001 From: tommi27 Date: Sun, 4 Aug 2019 15:56:15 +0200 Subject: [PATCH] started chessboard problem --- assignment1-18/chessboard.c | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 assignment1-18/chessboard.c diff --git a/assignment1-18/chessboard.c b/assignment1-18/chessboard.c new file mode 100644 index 0000000..be63ea9 --- /dev/null +++ b/assignment1-18/chessboard.c @@ -0,0 +1,68 @@ +#include +#include "./chessboard.h" + +void init_chessboard(struct chessboard * cb) { + int i; + for (i = 0; i < 8; i++) { + cb->position[1][i] = WHITE_PAWN; + cb->position[6][i] = BLACK_PAWN; + } + + cb->position[0][0] = WHITE_ROOK; + cb->position[0][1] = WHITE_KNIGHT; + cb->position[0][2] = WHITE_BISHOP; + cb->position[0][3] = WHITE_QUEEN; + cb->position[0][4] = WHITE_KING; + cb->position[0][5] = WHITE_BISHOP; + cb->position[0][6] = WHITE_KNIGHT; + cb->position[0][7] = WHITE_ROOK; + + cb->position[7][0] = BLACK_ROOK; + cb->position[7][1] = BLACK_KNIGHT; + cb->position[7][2] = BLACK_BISHOP; + cb->position[7][3] = BLACK_QUEEN; + cb->position[7][4] = BLACK_KING; + cb->position[7][5] = BLACK_BISHOP; + cb->position[7][6] = BLACK_KNIGHT; + cb->position[7][7] = BLACK_ROOK; + + int j; + for (i = 0; i < 8; i++) { + for (j = 2; j < 6; j++) { + cb->position[j][i] = EMPTY; + } + } + +} + +void print_chessboard(struct chessboard * cb) { + printf(" a b c d e f g h\n" + " ┌───┬───┬───┬───┬───┬───┬───┬───┐\n"); + + int i; + for (i = 7; i >= 0; i--) { + + printf("%d │", i + 1); + + int j; + for (j = 0; j < 8; j++) { + printf(" %s │", utf_8_pieces[cb->position[i][j]]); + } + putchar('\n'); + + if (i != 0) { + printf(" ├───┼───┼───┼───┼───┼───┼───┼───┤\n"); + } + } + + printf(" └───┴───┴───┴───┴───┴───┴───┴───┘\n" + " a b c d e f g h\n"); + +} + +enum mstatus move( + struct chessboard * cb, enum player p, + const char * from, const char * to) +{ + +}