Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.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++初学者,但我必须面对这个复杂的问题。 我基本上需要设计一些策略来制作一个简单的“骰子扑克游戏”,类似于Witcher的游戏。我提出了一个依赖于4个参数的策略,我想通过暴力地尝试所有这些组合来分析哪种参数组合产生最好的结果。 该策略由以下结构表示: typedef struct SOLUTION { const char Name[32]; const char ShortName[8]; void(* Init)(); int(* AI)(int, int, int, int); } SOLUTION;_C++_Pointers_Lambda_Anonymous Function_Stdbind - Fatal编程技术网

动态生成的函数的部分应用程序将作为函数指针传递给结构 基本上我是C++初学者,但我必须面对这个复杂的问题。 我基本上需要设计一些策略来制作一个简单的“骰子扑克游戏”,类似于Witcher的游戏。我提出了一个依赖于4个参数的策略,我想通过暴力地尝试所有这些组合来分析哪种参数组合产生最好的结果。 该策略由以下结构表示: typedef struct SOLUTION { const char Name[32]; const char ShortName[8]; void(* Init)(); int(* AI)(int, int, int, int); } SOLUTION;

动态生成的函数的部分应用程序将作为函数指针传递给结构 基本上我是C++初学者,但我必须面对这个复杂的问题。 我基本上需要设计一些策略来制作一个简单的“骰子扑克游戏”,类似于Witcher的游戏。我提出了一个依赖于4个参数的策略,我想通过暴力地尝试所有这些组合来分析哪种参数组合产生最好的结果。 该策略由以下结构表示: typedef struct SOLUTION { const char Name[32]; const char ShortName[8]; void(* Init)(); int(* AI)(int, int, int, int); } SOLUTION;,c++,pointers,lambda,anonymous-function,stdbind,C++,Pointers,Lambda,Anonymous Function,Stdbind,现在,我得到的是一个“高度”参数化函数: static int AI_noRiskVar (int a, int b, int c, int d, int opponent_id, int bet, int state, int dice) { //do some stuff based on parameters a, b, c, d and the rest of parameters (which represent the game actual state) } 除此之外,我

现在,我得到的是一个“高度”参数化函数:

static int AI_noRiskVar (int a, int b, int c, int d, int opponent_id, int bet, int state, int dice) {
    //do some stuff based on parameters a, b, c, d and the rest of parameters (which represent the game actual state)
}
除此之外,我还有一个简单的API,它使我能够测试任意数量的策略。我所要做的就是将它们放入
解决方案
结构的数组中

我提出了这个计划,试图利用
std::bind函数
,它应该能够将我的
AI_noRiskVar
函数部分应用于一些参数a、b、c、d:

SOLUTION Solution[83521]
int kauntr = 0;
for (int a = 3; a < 20; ++a) {
    for (int b = 3; b < 20; ++b) {
        for (int c = 3; c < 20; ++c) {
            for (int d = 3; d < 20; ++d) {
                // the identification of which struct contains which strategy is not important now
                Solution[kauntr] = (SOLUTION){"fixed length string of 31 chars", "7 chars", NULL, std::bind(&AI_noRiskVar, a, b, c, d)};
            }
        }
    }
}
解决方案[83521]
int-kauntr=0;
对于(int a=3;a<20;++a){
对于(int b=3;b<20;++b){
对于(int c=3;c<20;++c){
对于(int d=3;d<20;++d){
//现在识别哪个结构包含哪个策略并不重要
解决方案[kauntr]=(解决方案){“31个字符的固定长度字符串”,“7个字符”,NULL,std::bind(&AI_noRiskVar,a,b,c,d)};
}
}
}
}
我想创建一个结构数组,其中每个结构都有一个a、b、c、d参数的组合,这些参数部分地输入到它的AI函数I中。E通过生成的结构之一测试策略的所有可能配置。 问题是,std::bind并没有返回完全属于
int*(int,int,int,int)
类型的部分应用函数,而是属于
\u bind(int*(int,int,int,int))

有没有关于如何解决类型问题的建议?还是我遗漏了一些关键的东西? 我的手C,几乎所有其他主要的编程语言,但不是C++,我觉得甚至在语法Aurnt类型中丢失。

编辑1: 我无法更改
struct SOLUTION
的定义或声明,因此我需要精确到上面描述的类型。有可能吗?
另外,如果你想介绍一些C++特定的库函数或方法,你能演示一下如何在我的问题的上下文中使用它们,这将帮助我理解C++的编码方式。< / P>不要试图从函数绑定参数中获取函数指针:它将不起作用。本质上,函数指针无法捕获其他状态。相反,请使用
std::function
。这些行为类似,但可以捕获状态。在C++中,不需要<代码> TyPulf< /COD>结构和类,只写<代码>结构解决方案{…};<代码>,然后您仍然可以像在代码中一样使用它。注意,在所有的大写字母中写结构名称有点奇怪;我建议你只大写第一个字母,这种类型的变量应该以小写字母开头。这能回答你的问题吗?我无法更改解决方案结构定义。另外,整个API是为我预定义的。它是由一个更像C的人写的,我也是。