use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class DiffGameSpeedTest method main.
public static void main(String[] args) {
DiffGame dg = new DiffGame();
ElapsedTimer t = new ElapsedTimer();
Types.ACTIONS[] actions = new Types.ACTIONS[2];
int nTicks = (int) 3e7;
ElapsedCpuTimer timer = new ElapsedCpuTimer();
AbstractMultiPlayer player1, player2;
player1 = new controllers.multiPlayer.sampleRandom.Agent(dg, timer, 0);
player2 = new controllers.multiPlayer.sampleRandom.Agent(dg, timer, 1);
int updateTick = 100;
for (int i = 0; i < nTicks; i++) {
// update the chosen actions every so often
if (i % updateTick == 0) {
actions[0] = player1.act(dg, timer);
actions[1] = player2.act(dg, timer);
}
// advance anyway
dg.advance(actions);
}
System.out.println(dg.getGameScore());
System.out.println(t);
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class SimpleBattleTest method main.
public static void main(String[] args) {
int nSteps = (int) 2e3;
int nPlayers = 2;
int[] actions = new int[nPlayers];
Random rand = new Random();
SimpleBattleState state = new SimpleBattleState();
state = state.copyState();
StatSummary[] scoreStats = new StatSummary[] { new StatSummary(), new StatSummary() };
ElapsedTimer t = new ElapsedTimer();
BattleView view = new BattleView(state);
if (view != null) {
new JEasyFrame(view, "Simple Battle Game");
}
for (int i = 0; i < nSteps; i++) {
for (int j = 0; j < nPlayers; j++) {
actions[j] = rand.nextInt(state.nActions());
}
// now advance the game to the next step
state.next(actions);
for (int j = 0; j < state.score.length; j++) {
scoreStats[j].add(state.score[j]);
}
if (view != null) {
view.repaint();
try {
Thread.sleep(delay);
} catch (Exception e) {
}
}
}
for (int i = 0; i < scoreStats.length; i++) {
System.out.println("Player: " + i);
System.out.println(scoreStats[i]);
System.out.println();
}
System.out.println(t);
System.out.println();
System.out.println(nSteps + " states written");
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class BattleTestEA method runTrials.
public static StatSummary runTrials(EvoAlg ea, SolutionEvaluator evaluator, int nTrials, int nFitnessEvals) {
// record the time stats
StatSummary ss = new StatSummary();
for (int i = 0; i < nTrials; i++) {
ElapsedTimer t = new ElapsedTimer();
evaluator.reset();
System.out.println("Running trial: " + i);
int[] solution = ea.runTrial(evaluator, nFitnessEvals);
System.out.println(t);
System.out.println("Solution: " + Arrays.toString(solution));
System.out.println(evaluator.logger().ss);
System.out.println();
evaluator.logger().report();
System.out.println();
ss.add(evaluator.logger().ss.max());
}
return ss;
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class ParameterSettingsTest method main.
public static void main(String[] args) {
DefaultParams defParams = new DefaultParams();
defParams.shipSteer = 1;
// GameParameters params = new GameParameters().injectValues(evolvableParams);
GameParameters params = new GameParameters().injectValues(defParams);
SimpleEvaluator eval = new SimpleEvaluator();
int nTrials = 30;
eval.evaluate(defParams, nTrials);
// exit if we're done
// comment this out to proceed to visual test
// System.exit(0);
int startLevel = 1;
int nLives = 5;
boolean visible = true;
int nTicks = 10000;
AsteroidsGameState gameState = new AsteroidsGameState().setParams(params).initForwardModel();
Game game = new Game(gameState, visible);
ElapsedTimer t = new ElapsedTimer();
game.run(nTicks);
System.out.println(t);
// System.out.println(gameState.score);
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class RandomGameVisualTest method runVisually.
public static void runVisually(ParamValues evoParams) {
GameParameters params = new GameParameters().injectValues(evoParams);
int startLevel = 1;
int nLives = 5;
boolean visible = true;
int nTicks = 10000;
AsteroidsGameState gameState = new AsteroidsGameState().setParams(params);
Game game = new Game(gameState, visible);
ElapsedTimer t = new ElapsedTimer();
game.run(nTicks);
System.out.println(t);
// System.out.println(gameState.score);
}
Aggregations