예제 #1
0
파일: codegen.c 프로젝트: mushrom/cminus
parse_node_t *trim_tree( parse_node_t *tree ){
	parse_node_t 	*ret = NULL;

	if ( tree ){
		ret = tree;
		if (( ret->next == NULL || tree->next->type == T_NULL ) &&
				( tree->down != NULL && !tree->down->next )
				&& tree->type != T_CALL ){

			ret = trim_tree( tree->down );
			free( tree );

		} else if ( tree->down != NULL && !tree->down->next
				&& tree->type != T_STATEMNT && tree->type != T_CALL ){

			ret = trim_tree( tree->down );
			ret->next = trim_tree( tree->next );
			free( tree );

		} else {
			ret->down = trim_tree( tree->down );
			ret->next = trim_tree( tree->next );
		}
	}

	return ret;
}
/**
 * Makes a move, Using Alph-Beta Pruning
 *@param board the game board visualization
 *@param score my score
 *@param opponentScore the opponent's score
 *@param pointsRemaining how many points are left this game
 *@return my move
 */
int AlphaBetaAI::makeMove(int* board, int score, int opponentScore, int pointsRemaining) {
    AlphaBetaNode* root = trim_tree(board, score, opponentScore, pointsRemaining);

    if (!run) {
        run = true;
        pthread_create(&thread, NULL, ab_thread, (void *)this);
    }

    int start = time(0);
    while (time(0)-start < 1);

    return best_move(root);
}