summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c92
1 files changed, 86 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 49db27a..62b4692 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,11 +1,91 @@
-#include <ncurses.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "config.h"
+#include "pieces.h"
+
+
+void print_board(int board[BOARD_SIZE][BOARD_SIZE]) {
+ for (int rank = BOARD_SIZE - 1; rank >= 0; rank--) {
+ printf("%i|", rank + 1);
+ for (int file = 0; file < BOARD_SIZE; file++) {
+ int piece = board[rank][file];
+ printf("%s ", pieces[piece]);
+ }
+ printf("\n");
+ }
+ printf(" a b c d e f g h\n");
+}
+
+void parse_FEN(char* FEN, int board[BOARD_SIZE][BOARD_SIZE]) {
+ // TODO: parse everything, not position only
+ int rank = 7;
+ int file = 0;
+ size_t lenght = strlen(FEN);
+
+ for (int k = 0; k < lenght; k++) {
+ if (FEN[k] > '0' && FEN[k] <= '8') {
+ int last_file = file + FEN[k] - '0';
+ for (file; file < last_file; file++) {
+ board[rank][file] = EMPTY;
+ }
+ } else {
+ switch (FEN[k]) {
+ case 'r':
+ board[rank][file] = BLACK | ROOK;
+ break;
+ case 'R':
+ board[rank][file] = ROOK;
+ break;
+ case 'n':
+ board[rank][file] = BLACK | KNIGHT;
+ break;
+ case 'N':
+ board[rank][file] = KNIGHT;
+ break;
+ case 'b':
+ board[rank][file] = BLACK | BISHOP;
+ break;
+ case 'B':
+ board[rank][file] = BISHOP;
+ break;
+ case 'q':
+ board[rank][file] = BLACK | QUEEN;
+ break;
+ case 'Q':
+ board[rank][file] = QUEEN;
+ break;
+ case 'k':
+ board[rank][file] = BLACK | KING;
+ break;
+ case 'K':
+ board[rank][file] = KING;
+ break;
+ case 'p':
+ board[rank][file] = BLACK | PAWN;
+ break;
+ case 'P':
+ board[rank][file] = PAWN;
+ break;
+ case '/':
+ rank--;
+ file = -1; // so that it becomes 0
+ break;
+ case ' ':
+ return;
+ default:
+ board[rank][file] = KNIGHT;
+ }
+ file++;
+ }
+ }
+}
int main() {
- initscr();
- printw("Hello, world!");
- refresh();
- getch();
- endwin();
+ int board[BOARD_SIZE][BOARD_SIZE];
+ parse_FEN(DEFAULT_FEN, board);
+ print_board(board);
return 0;
}