Defining Agents and Games in a JSON file

Agents

Agents can be defined in a JSON file to make it easier to specify the precise details - for example when running tournaments between multiple agents.

A few examples of increasing complexity are shown below:

{
	"class" : "players.simple.RandomPlayer",
}

The first way is to simply specify any class that implements AbstractPlayer with a no-arguments constructor. The class field is mandatory, and any JSON file not containing this will be rejected.

{
	"class":"players.simple.OSLAHeuristic",
	"heuristic" : {
		"class" : "games.coltexpress.ColtExpressHeuristic",
		"maxLoot" : 500,
		"BULLET_CARDS" : -1.0,
    		"BULLETS_PLAYER" : 0.5,
		"BULLETS_ENEMY" : 0.0,
		"LOOT" : 0.5
	}	
}

The second example above now references OSLAHeuristic, which is not an AbstractPlayer, but sub-classes TunableParameters. In this case the remainder of the json will be used to create this parameterised object and then call the instantiate() method. See the separate documentation on TunableParameters for much more detail.

The third exmaple below then creates an MCTS agent using the same approach. For details on the contents, see the MCTS documentation.

{
        "class" : "players.mcts.MCTSParams",
        "selectionPolicy" : "SIMPLE",
        "rolloutLength" : 300,
        "information" : "Open_Loop",
        "opponentTreePolicy" : "SelfOnly",
        "K" : 1.0,
        "exploreEpsilon" : 0.10,
        "maxTreeDepth" : 30,
        "treePolicy" : "EXP3",
        "rolloutType" : "CLASS",
	"rolloutClass" : {
		"class" : "games.dicemonastery.heuristics.Advantage003",
		"args" : ["Adv002_0711.csv", true],
	},
	"actionHeuristic" : {
		"class" : "games.dicemonastery.heuristics.Advantage003",
		"args" : ["Adv002_0711.csv", false],
	},
	"progressiveWideningConstant" : 3.0,
	"progressiveWideningExponent" : 0.1,
	"MAST" : "Tree",
	"MASTBoltzmann" : "0.05",
        "budgetType" : "BUDGET_TIME",
        "budget" : 10000,
        "breakMS" : 0
}

The key point to note is that any arbitrary class can be instantiated in this way without needing to implement ITunableParameters by using the supported convention of providing arguments for any constructor in an args tag, which must be in the order they appear in the Constructor to be used:

	{
		"class" : "name of class",
		"args" : ["argvalueOne", "argValueTwo", ... ]
	}

Or, more concretely (admittedly using a hallucinated class):

	{
		"class" : "games.catan.CatanHeuristic",
		"args" : [3, "WOOL", 6.9, "ALWAYS", {"class" : "games.catan.heuristics.AlwaysTradeHeuristic"} ]
	}

As shown in this example, these argValues can themselves be nested class objects (and so on recursively).

Games

GameParameters that extend TunableParameters can also be specified in exactly the same way as agents.

A simple example is:

{
	"class" : "games.tictactoe.TicTacToeGameParameters",
	"gridSize" : 4
}