this.moveHistory = new ArrayList<List<GdlTerm>>();
this.stateHistory = new ArrayList<Set<GdlSentence>>();
this.stateTimeHistory = new ArrayList<Date>();
this.errorHistory = new ArrayList<List<String>>();
JSONArray theMoves = theMatchObject.getJSONArray("moves");
for (int i = 0; i < theMoves.length(); i++) {
List<GdlTerm> theMove = new ArrayList<GdlTerm>();
JSONArray moveElements = theMoves.getJSONArray(i);
for (int j = 0; j < moveElements.length(); j++) {
theMove.add(GdlFactory.createTerm(moveElements.getString(j)));
}
moveHistory.add(theMove);
}
JSONArray theStates = theMatchObject.getJSONArray("states");
for (int i = 0; i < theStates.length(); i++) {
Set<GdlSentence> theState = new HashSet<GdlSentence>();
SymbolList stateElements = (SymbolList) SymbolFactory.create(theStates.getString(i));
for (int j = 0; j < stateElements.size(); j++)
{
theState.add((GdlSentence)GdlFactory.create("( true " + stateElements.get(j).toString() + " )"));
}
stateHistory.add(theState);
}
JSONArray theStateTimes = theMatchObject.getJSONArray("stateTimes");
for (int i = 0; i < theStateTimes.length(); i++) {
this.stateTimeHistory.add(new Date(theStateTimes.getLong(i)));
}
if (theMatchObject.has("errors")) {
JSONArray theErrors = theMatchObject.getJSONArray("errors");
for (int i = 0; i < theErrors.length(); i++) {
List<String> theMoveErrors = new ArrayList<String>();
JSONArray errorElements = theErrors.getJSONArray(i);
for (int j = 0; j < errorElements.length(); j++)
{
theMoveErrors.add(errorElements.getString(j));
}
errorHistory.add(theMoveErrors);
}
}
this.goalValues = new ArrayList<Integer>();
try {
JSONArray theGoalValues = theMatchObject.getJSONArray("goalValues");
for (int i = 0; i < theGoalValues.length(); i++) {
this.goalValues.add(theGoalValues.getInt(i));
}
} catch (JSONException e) {}
// TODO: Add a way to recover cryptographic public keys and signatures.
// Or, perhaps loading a match into memory for editing should strip those?
if (theMatchObject.has("playerNamesFromHost")) {
thePlayerNamesFromHost = new ArrayList<String>();
JSONArray thePlayerNames = theMatchObject.getJSONArray("playerNamesFromHost");
for (int i = 0; i < thePlayerNames.length(); i++) {
thePlayerNamesFromHost.add(thePlayerNames.getString(i));
}
}
if (theMatchObject.has("isPlayerHuman")) {
isPlayerHuman = new ArrayList<Boolean>();
JSONArray isPlayerHumanArray = theMatchObject.getJSONArray("isPlayerHuman");
for (int i = 0; i < isPlayerHumanArray.length(); i++) {
isPlayerHuman.add(isPlayerHumanArray.getBoolean(i));
}
}
}