if (tolower(Piece_code(promoted)) != move_string[4])
continue;
}
return move;
result = move;
break;
}
}
return 0;
MoveList_free(&moves);
return result;
}
CBoard_T Position_parse(Position_T self, CBoard_T board) {
printf("Commands: %s\n", self->command);
int count = 0;
char *token = Position_token(self);
do {
printf("Token %d: %s\n", ++count, token);
if (strcmp(token, "position") == 0) {
printf("FOUND position\n");
token = Position_token_next(self);
if (strcmp(token, "startpos") == 0) {
printf("FOUND startpos\n");
board = CBoard_fromFEN(board, start_position);
} else if (strcmp(token, "fen") == 0) {
token = Position_token_n(self, 6);
printf("fen: %s\n", token);
board = CBoard_fromFEN(board, token);
continue;
} else {
printf("Unknown argument after position\n");
assert(0);
}
}
if (strcmp(token, "moves") == 0) {
printf("FOUND moves\n");
CBoard_print(board);
while ((token = Position_token_next(self))) {
Move move = parse_move(board, token);
if (move) {
make_move(board, move, 0);
CBoard_print(board);
} else {
printf("Invalid move %s!\n", token);
assert(0);
}
}
}
} while ((token = Position_token_next(self)));
return board;
}
int main(void) {
init_all();
CBoard_T board = CBoard_fromFEN(NULL, start_position);
Move move = parse_move(board, "e2e4");
if (move) {
make_move(board, move, 0);
CBoard_print(board);
} else
printf("Illegal move!\n");
CBoard_T board = NULL;
Position_T position;
position =
Position_new(" position \t fen " start_position " moves e2e4 e7e5");
board = Position_parse(position, board);
Position_free(&position);
CBoard_free(&board);
return 0;
}