1

调用以下函数时,我不断收到错误消息。错误是bestboard在调用 searchTree.m 期间未分配输出参数(可能还有其他参数)。

function [alpha,bestboard] = searchTree(board,depth,alpha,beta,turn)

if(depth<=0)

    alpha=calculateHeuristic(board,changeTurn(turn));
    bestboard=board;
    return
else
    child=GenerateChild(board,turn);
    a=size(child,3);

    if(turn==2)

        turn=changeTurn(turn);
        for i=1:a    
            [score,aboard]=searchTree(child(:,:,i),depth-1,alpha,beta,turn);
            if(score>alpha)
                alpha=score;
                bestboard=child(:,:,i);
            end
        end

        return
    else

        for j=1:a
            turn=changeTurn(turn);
            [scor,bboard]=searchTree(child(:,:,j),depth-1,alpha,beta,turn);
            if(scor<beta)
                beta=scor;
                bestboard=child(:,:,j);
                alpha=beta;
            end

        end

    return
    end
end
4

1 回答 1

3

这是因为bestboard分配在一个if没有别的。在您的函数中,ifturn ~= 2和then不会被分配给。考虑在开始时为其分配一个默认值?scor >= betadepth > 0bestboard

于 2013-04-11T11:53:21.467 回答