Esempio n. 1
0
static int
handle_mate_search(struct node *node)
{
	if (node->beta <= -max_value + 2) {
		/*
		 * Any move would raise alpha above such beta.
		 * A draw would raise alpha above such beta.
		 * The only way alpha would not be raised, is if
		 * this if the player is checkmated.
		 */

		if (is_checkmate(node))
			node->value = -max_value;
		else
			node->value = node->beta;

		return mate_search_handled;
	}
	else if (node->alpha >= max_value - 2) {
		/*
		 * Nothin can raise such alpha. A checkmate on
		 * next move would just return the same value here.
		 */
		node->value = node->alpha;

		return mate_search_handled;
	}

	return 0;
}
Esempio n. 2
0
int main()
{
	int n, g_x, g_y;
	int flag = 0;
	while(scanf("%d%d%d", &n, &g_x, &g_y) && (n || g_x || g_y)){
		flag = 0;
		initialization(board);
		char _type[100] = {0};
	    int x[100] = {0}, y[100] = {0};
		int i = 0;
		while(n--){
		/*	char _type;
			int x, y;*/
			getchar();
			scanf("%c%d%d", &_type[i], &x[i], &y[i]);
			board[x[i] + 1][y[i] + 1] = 100;
			i++;
		}
		n = i;
		for(int i = 0; i < n; i++){
				switch(_type[i]){
				case 'G':flag = red_gereral(board, x[i], y[i], g_y); break;
				case 'R':red_chariot(board, x[i], y[i]); break;
				case 'H':red_horse(board, x[i], y[i]); break;
				case 'C':red_cannon(board, x[i], y[i]); break;
			}
		}
		if(is_checkmate(board, g_x, g_y) && !flag){
			printf("YES\n");
		}
		else printf("NO\n");

	}
	return 0;
}
Esempio n. 3
0
static void
add_move(move m)
{
    mtx_lock(&game_mutex);


    char move_str[MOVE_STR_BUFFER_LENGTH];

    (void) print_move(current_position(), m, move_str, mn_san, turn());
    if (game_append(game, m) == 0) {
        engine_process_move(m);
        debug_engine_set_player_to_move(turn());
        tracef("repro: %s", move_str);

        if (is_end()) {
            game_started = false;

            if (is_checkmate() && turn() == white)
                puts("0-1 {Black mates}");
            else if (is_checkmate() && turn() == black)
                puts("1-0 {White mates}");
            else if (is_stalemate())
                puts("1/2-1/2 {Stalemate}");
            else if (is_draw_by_insufficient_material())
                puts("1/2-1/2 {No mating material}");
            else if (is_draw_by_repetition())
                puts("1/2-1/2 {Draw by repetition}");
            else if (is_draw_by_50_move_rule())
                puts("1/2-1/2 {Draw by 50 move rule}");
            else
                abort();
        }
    }

    mtx_unlock(&game_mutex);
}
Esempio n. 4
0
BOOL repetition_draw(struct t_board *board)
{
    int i;
    int reps = 0;

    if (board->fifty_move_count >= 4) {
        if (board->fifty_move_count >= 100) return !is_checkmate(board);
        i = 4;
        do
        {
            if (draw_stack[draw_stack_count - i] == board->hash) {
                if (TRUE || draw_stack_count - i > search_start_draw_stack_count)
                    return TRUE;
                reps++;
                if (reps == 2)
                    return TRUE;
            }
            i += 2;
        } while (board->fifty_move_count >= i);
    }
    return FALSE;
}