JBench 1

From CS227B Wiki

Jump to: navigation, search

Below is the code which defines the JBench 1 state machine benchmark. To see people's results on this benchmark, visit state machine benchmarks.

private void testStateMachine(StateMachine sm) throws Exception {
	long time = runDepthCharges("connectfour", sm, 2000);
	time += runDepthCharges("nineboardtictactoe", sm, 1000);
	time += runDepthCharges("breakthroughsmall", sm, 1000);
	time += runDepthCharges("tictactoelarge", sm, 2000);
	System.out.println("Testing state machine took " + time + " ms");
}

private long runDepthCharges(String game, StateMachine sm, int num) throws Exception {
	sm.initialize(KifReader.read("games" + File.separator + "rulesheets" + 
                                    File.separator + game + ".kif"));
	
	long time = System.currentTimeMillis();
	for (int i = 0; i < num; i++) {
		runDepthCharge(game, sm);
		sm.doPerMoveWork();
	}
	return System.currentTimeMillis() - time;
}

private void runDepthCharge(String game, StateMachine sm) throws Exception {
	MachineState state = sm.getInitialState();
	
	while(! sm.isTerminal(state)) {
		state = sm.getRandomNextState(state);
		
		for(Role role : sm.getRoles()) {
			sm.getGoal(state, role);
			sm.getLegalMoves(state, role);
		}
	}
}
Personal tools