コード例 #1
0
static void
test_fen_basic(void)
{
	struct position *position;
	struct position *next;
	move move;
	char str[FEN_BUFFER_LENGTH + MOVE_STR_BUFFER_LENGTH];
	static const char *empty_fen = "8/8/8/8/8/8/8/8 w - - 0 1";
	unsigned hm, fm;
	int ep_index;
	enum player turn;

	position = position_allocate();
	next = position_allocate();
	assert(position_print_fen_full(position, str, 0, 1, 0, white)
	    == str + strlen(empty_fen));
	assert(strcmp(empty_fen, str) == 0);
	assert(NULL != position_read_fen_full(position, start_position_fen,
	    &ep_index, &fm, &hm, &turn));
	assert(ep_index == 0);
	assert(hm == 0 && fm == 1 && turn == white);
	assert(position_print_fen_full(position, str, 0, 1, 0, white)
	    == str + strlen(start_position_fen));
	assert(strcmp(str, start_position_fen) == 0);
	move = create_move_t(str_to_index("e2", white),
	    str_to_index("e4", white),
	    mt_pawn_double_push, pawn, 0, false);
	setup_registers();
	make_move(next, position, move);
	assert(position_piece_at(next, str_to_index("e2", black)) == nonpiece);
	assert(position_piece_at(next, str_to_index("e4", black)) == pawn);
	position_destroy(position);
	position_destroy(next);
}
コード例 #2
0
static void
test_coordinates(void)
{
	assert(is_coordinate("g6"));
	assert(!is_coordinate("g9"));
	assert(!is_coordinate("g0"));
	assert(!is_coordinate("6"));
	assert(is_coordinate("g6 lorem ipsum"));
	assert(!is_coordinate("lorem ipsum"));

	assert(str_to_index("g6", white) == ind(rank_6, file_g));
	assert(str_to_index("g6", black) == flip_i(ind(rank_6, file_g)));
}
コード例 #3
0
ファイル: fen.c プロジェクト: GBuella/Taltos
static int
coor_str_to_index(const char *str, enum player turn, jmp_buf jb)
{
	if (!is_file(str[0]) || !is_rank(str[1])) longjmp(jb, 1);

	return str_to_index(str, turn);
}