Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C Otherlo极小极大算法不起作用_C_Algorithm_Minimax - Fatal编程技术网

C Otherlo极小极大算法不起作用

C Otherlo极小极大算法不起作用,c,algorithm,minimax,C,Algorithm,Minimax,我正在尝试做一个极大极小算法,但是我的函数没有返回正确的位置。它返回最深的节点。我希望它能以最好的方式返回。这是我的密码: pos minimax(game* g, strategy_config sc) { int points = 0; sc.minimax_config.heuristic(g, sc.minimax_config.hc); pos p, p2; int search_depth = sc.minimax_config.ply; fo

我正在尝试做一个极大极小算法,但是我的函数没有返回正确的位置。它返回最深的节点。我希望它能以最好的方式返回。这是我的密码:

pos minimax(game* g, strategy_config sc)
{
    int points = 0;
    sc.minimax_config.heuristic(g, sc.minimax_config.hc);
    pos p, p2;
    int search_depth = sc.minimax_config.ply;
    for (p.r = 0; p.r < g->b->nrows; p.r++) 
    {
        for (p.c = 0; p.c < g->b->ncols; p.c++) 
        {
            game* copy = g;
            apply_move(copy, p);
            if (sc.minimax_config.heuristic(copy, sc.minimax_config.hc) 
                > points && sc.minimax_config.ply > 0)
            {
                if (sc.minimax_config.ply == search_depth) 
                {
                    p2 = p;
                }
                sc.minimax_config.ply = sc.minimax_config.ply - 1;
                minimax(copy, sc);
            }
        }
    }
    return p2;
}

发布的代码不可编译(并且不是MVSE),其中定义为:
游戏
pos
。代码缺少以下语句:
typedef union strategy\u config strategy\u config。其中是
apply\u move()
minimax()
的定义。你想用这段代码做什么:
union-strategy\u-config{minimax\u-config minimax\u-config;}?此语句:
如果(sc.minimax\u config.heuristic(copy,sc.minimax\u config.hc)>点和&sc.minimax\u config.ply>0)
正在检查sc.minimax\u config.heuristic()返回的值是否大于零。那么为什么变量
指向
?只需将0与所发布代码的哪一部分产生不正确的值进行比较即可。对
copy
的任何修改都会修改
g
,因为它是指向相同数据的指针。
struct edge_corner_weight {
    unsigned int edge_weight;
    unsigned int corner_weight;
};

union heuristic_config {
    unsigned int edge_weight;
    struct edge_corner_weight edge_corner_weight;
};

typedef union heuristic_config heuristic_config;

struct minimax_config {
    int (*heuristic)(game*, heuristic_config);
    heuristic_config hc;
    unsigned int ply;
};

typedef struct minimax_config minimax_config;

union strategy_config {
    minimax_config minimax_config;
};