从 GAMUT 生成 Polymatrix 游戏

Generating Polymatrix games from GAMUT

我正在尝试从 GAMUT java 库生成 Polymatrix 游戏。

    try {
        PolymatrixGame polyGame = new PolymatrixGame();
        
        polyGame.setParameter("players", nbOfPlayers); //nbOfPlayers = 3L;
        polyGame.setParameter("actions", nbOfActions); //nbOfActions is a Vector<String> with three entries: each equal "2".
        polyGame.setParameter("graph", "RandomGraph");
        
        polyGame.setParameter("graph_params", new ParamParser(new String[] {"-nodes", "" + nbOfPlayers, "-edges", "" + 3, "-sym_edges", "1", "-reflex_ok", "0"}));
        polyGame.setParameter("subgame", "Chicken");
        polyGame.setParameter("subgame_params", new ParamParser());
        
        polyGame.initialize();

        polyGame.doGenerate();
        
    } catch (Exception e) {
        e.printStackTrace();
    }

我收到以下错误:

FATAL ERROR: Unable to generate polymatrix game (subgame Chicken)

java.lang.NullPointerException

我一直在挖掘源代码,但找不到错误的根源。错误消息本身也没什么用。

最后,我试图生成一个随机的 Polymatrix 游戏,其中包含给定的玩家数量和每个玩家的给定动作数。

在深入挖掘源代码和调试之后, 我发现是什么导致了 NullPointerException.

GAMUT 假定您要求使用命令行生成游戏。它将命令的参数存储在 Global class.

中名为 gArgsString 数组变量中
  // -- Original command line
  public static String[] gArgs;

当生成 PolyMatrix 游戏时,调用 GameOutput class 中的方法,将 StringgArgs 数组更改为正常 String 然后存储在相关的 PolyMatrix 对象中。提到的方法如下。

public static String arrayToString(String[] args, String sep)
{
StringBuffer buff=new StringBuffer();
for(int i=0; i<args.length; i++) {
    buff.append(args[i]);
    if (i!=args.length-1)
    buff.append(sep);
}

return buff.toString();
}

Gameclass中调用如下。 GameOutput.arrayToString(Global.gArgs, " ")

如果 Global.gArgsnull,那么显然会抛出 NullPointerException。这正是原始 post 中代码示例中发生的情况,因为从未设置 Global.args

快速解决方案:将 Global.gArgs 设置为无意义的内容,例如 Global.gArgs = new String[]{""};

最佳解决方案:实际上将 Global.gArgs 设置为 String 的数组,其中包含您要从中生成游戏时给出的参数命令行。 像 Global.gArgs = new String[]{"-players", "3", "-actions", "2", "-graph", "RandomGraph", "-graph_params", "[-nodes 3 - edges 3 - sym_edges 1 -reflex_ok 0]", "-subgame", "Chicken", "-subgame_params", "[]"}

(如果游戏实际上是从命令行生成的,'best' 解决方案给出的示例可能与 Global.gArgs 的实际值略有不同。

然而,奇怪的是,像 PrisonersDilemma 和 Chicken 这样的简单游戏不需要设置 gArgs 变量。