Skip to content

Commit

Permalink
Adjustments to optimization experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
tylorr committed Feb 3, 2012
1 parent f762d0d commit b237269
Showing 1 changed file with 69 additions and 1 deletion.
70 changes: 69 additions & 1 deletion game/Exec.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public static void main(String[] args)

//this can be used for numerical testing (non-visual, no delays)
//exec.runExperiment(new MyPacMan(),new RandomGhosts(),100);
exec.runGameTimed(new MyPacMan(), new RandomGhosts(), true);
exec.runOptimizeExperiment(new Legacy(), 10, 20, 40, 40, 60, 0, 10, 0, 10, 5);
//exec.runGameTimed(new MyPacMan(), new RandomGhosts(), true);


//run game without time limits (un-comment if required)
Expand Down Expand Up @@ -164,6 +165,73 @@ public void runMyExperiment(GhostController ghostController,int trials, int min,
System.out.println(bestScore);
}

public void runOptimizeExperiment(
GhostController ghostController, int trials,
int close_min, int close_max,
int blue_min, int blue_max,
int power_min, int power_max,
int junc_min, int junc_max,
int step)
{
PacManController pacManController = new MyPacMan();

int bestClose = -1;
int bestBlue = -1;
int bestPower = -1;
int bestJunc = -1;
double bestScore = Double.MIN_VALUE;

for (int close = close_min; close <= close_max; close += step) {
System.out.println("Tick: " + close);
for (int blue = blue_min; blue <= blue_max; blue += step) {
System.out.println("\tTick: " + blue);
for (int power = power_min; power <= power_max; power += step) {
System.out.println("\t\tTick: " + power);
for (int junc = junc_min; junc <= junc_max; junc += step) {
System.out.println("\t\t\tTick: " + junc);
MyPacMan.CLOSE_DIST = close;
MyPacMan.CLOSE_BLUE_DIST = blue;
MyPacMan.POWER_DIST = power;
MyPacMan.JUNC_DIST = junc;

double avgScore=0;

game=new _G_();

for(int i=0;i<trials;i++)
{
game.newGame();

while(!game.gameOver())
{
long due=System.currentTimeMillis()+G.DELAY;
game.advanceGame(pacManController.getAction(game.copy(),due),ghostController.getActions(game.copy(),due));
}

avgScore+=game.getScore();
}

avgScore /= trials;

if (avgScore > bestScore) {
bestScore = avgScore;
bestClose = close;
bestBlue = blue;
bestPower = power;
bestJunc = junc;
}
}
}
}
}

System.out.println("Best Close: " + bestClose);
System.out.println("Best blue: " + bestBlue);
System.out.println("Best power: " + bestPower);
System.out.println("Best junc: " + bestJunc);
System.out.println(bestScore);
}

/*
* Run game without time limit. Very good for testing as game progresses as soon as the controllers
* return their action(s). Can be played with and without visual display of game states. The delay
Expand Down

0 comments on commit b237269

Please sign in to comment.