Initial commit

This commit is contained in:
Ole Morud
2022-06-09 16:40:47 +02:00
commit c2228faa22

60
chess.c Normal file
View File

@@ -0,0 +1,60 @@
#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
#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));
}