}
private void runScramblerTest(GdlScrambler scrambler) throws SymbolFormatException, GdlFormatException {
GameRepository repo = GameRepository.getDefaultRepository();
for (String gameKey : repo.getGameKeys()) {
Game game = repo.getGame(gameKey);
List<Gdl> theScrambledRules = new ArrayList<Gdl>();
for(Gdl rule : game.getRules()) {
String renderedRule = rule.toString();
String renderedScrambledRule = scrambler.scramble(rule).toString();
String renderedUnscrambledRule = scrambler.unscramble(renderedScrambledRule).toString();
theScrambledRules.add(GdlFactory.create(renderedScrambledRule));
// If the scrambler claims that it scrambles the game, then the
// scrambled rules should be different than the original rules.
// Otherwise they should be identical.
if (scrambler.scrambles()) {
assertTrue(gameKey, !renderedRule.equals(renderedScrambledRule));
} else {
assertEquals(gameKey, renderedRule, renderedScrambledRule);
}
// One important property for any scrambler is that the original
// and the unscrambled Gdl must be the same. This guarantees that
// the server can correctly unscramble responses from the players.
assertEquals(gameKey, renderedRule, renderedUnscrambledRule);
}
// An important property for any scrambler is that the scrambled rules
// have the same physics as the regular rules. For example, the number
// of roles in each game should be the same, and the number of facts
// that are true in the initial state should be the same. There could
// be more thorough verification here, like looking at the number of
// legal joint moves in the first state, or simulating entire matches,
// but that would be expensive.
ProverStateMachine pNormal = new ProverStateMachine();
ProverStateMachine pScrambled = new ProverStateMachine();
pNormal.initialize(game.getRules());
pScrambled.initialize(theScrambledRules);
assertEquals(gameKey, pNormal.getRoles().size(), pScrambled.getRoles().size());
assertEquals(gameKey, pNormal.getInitialState().getContents().size(), pScrambled.getInitialState().getContents().size());
}
}