Exemple #1
0
std::string SquareBFSearch::get_best_string()
{
	text = std::string();
	for (uint32_t index = 0; index < length; ++index)
		text += char(ALPH_BEGIN);

	std::string best = text;
	uint32_t best_res = get_square_number(best);
	uint32_t index;
	uint32_t cand;

	do {
		for (index = length; index > 0 && text[index - 1] == ALPH_BEGIN + alph_size - 1; --index)
			text[index - 1] = ALPH_BEGIN;
		if (index > 0) {
			cand = get_square_number(text);
			if (cand > best_res) {
				best_res = cand;
				best = text;
			}
			++text[index - 1];
		}
	} while (index > 0);

	return best;
}
Exemple #2
0
/* ----------------------------------------------------------
   CHESS_STATE get_chess_state(CHESS_STATE_STR chess_state_str)
   
   purpose: gets a chess state from individual chess state
            component strings.
   ---------------------------------------------------------- */
CHESS_STATE get_chess_state(CHESS_STATE_STR chess_state_str)
{
		CHESS_STATE cs = {0};
		
		// parse the piece placement string
		cs = set_piece_placement(chess_state_str.piece_placement);

		// next move
		if (strcmp(chess_state_str.active_color,"w")==0 || strcmp(chess_state_str.active_color,"W")==0)
			cs.flg_is_white_move=1;
		else
			cs.flg_is_white_move=0;

		// castling
		cs.flg_black_queen_castle = (strstr(chess_state_str.castling_availability,"q")==NULL) ? 0 : 1;
		cs.flg_white_queen_castle = (strstr(chess_state_str.castling_availability,"Q")==NULL) ? 0 : 1;
		cs.flg_black_king_castle = (strstr(chess_state_str.castling_availability,"k")==NULL) ? 0 : 1;
		cs.flg_white_king_castle = (strstr(chess_state_str.castling_availability,"K")==NULL) ? 0 : 1;

		// enpassant
		if (get_square_number(chess_state_str.enpassant_square)<0)
			cs.flg_is_enpassant=0;
		else
		{
			cs.flg_enpassant_file=COL(get_square_number(chess_state_str.enpassant_square));
			if (cs.flg_enpassant_file>=0 && cs.flg_enpassant_file<8)
				cs.flg_is_enpassant=1;
		}

		// halfmove clock
		cs.half_move_clock = atoi(chess_state_str.half_move_clock);
		
		// fullmove number
		cs.full_move_number = atoi(chess_state_str.full_move_number);
		
		cs.parent=NULL;
		cs.child_head=NULL;
		cs.next=NULL;
		return cs;
}
Exemple #3
0
uint32_t SquareNMCS::sample(const std::string &text)
{
	if (length < text.size()) {
		std::cerr << "critical error\n";
		exit(0);
	}

	std::string suffix;
	while (suffix.size() < length - text.size())
		suffix += ALPH_BEGIN + rand() % alph_size;

	return get_square_number(text + suffix);
}