started chessboard problem

This commit is contained in:
Tommaso Rodolfo Masera 2019-08-04 15:56:15 +02:00
parent 2b21c9d23c
commit 56afe8c36e

View file

@ -0,0 +1,68 @@
#include <stdio.h>
#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)
{
}