commit c2228faa2249a260611096f1d1ce5ab14725e919 Author: Ole Morud Date: Thu Jun 9 16:40:47 2022 +0200 Initial commit diff --git a/chess.c b/chess.c new file mode 100644 index 0000000..88d19e1 --- /dev/null +++ b/chess.c @@ -0,0 +1,60 @@ + +#include +#include +#include + +#define E 0 /* empty */ +#define K 1 /* king */ +#define Q 2 /* queen */ +#define R 3 /* rook */ +#define B 4 /* bishop */ +#define N 5 /* knight */ +#define P 6 /* pawn */ + +#define WHITE 1 +#define BLACK -1 + +int main(){ + int *board; + init_board(board); + print_board(board); + + return 0; +} + + + +void print_board(int* board){ + wchar_t piece; + + // The unicode value for a white chess king is 0x2654 + // the following unicode 5 unicode characters are the + // other white chess pieces. (matches macro definitions) + // (https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode) + for(int i=0; i<8; i++){ + for(int j=0; j<8; j++){ + piece = 0x2654 + board[i]; + putwchar(piece); + } + putchar('\n'); + } +} + + + +void init_board(int *board){ + + // black pieces are prefixed by minus (-) + const int start[] = { + -R,-N,-B,-Q,-K,-B,-N,-R, + -P,-P,-P,-P,-P,-P,-P,-P, + E, E, E, E, E, E, E, E, + E, E, E, E, E, E, E, E, + E, E, E, E, E, E, E, E, + E, E, E, E, E, E, E, E, + P, P, P, P, P, P, P, P, + R, N, B, Q, K, B, N, R + }; + + memcpy(board, start, sizeof(start)); +}