Skip to content
Snippets Groups Projects
Commit 9ab8ea10 authored by Piers Williams's avatar Piers Williams
Browse files

Modified the timer to work better

parent 4a0b1839
No related branches found
No related tags found
No related merge requests found
......@@ -5,13 +5,20 @@ package battle.controllers.Piers;
*/
public class GameTimer {
long startTime;
long timeBudget;
private long startTime;
private long timeBudget;
private boolean timeSet = false;
public GameTimer() {
startTime = System.nanoTime();
}
public GameTimer(long budget) {
this();
setTimeBudgetMilliseconds(budget);
}
public long elapsed() {
return System.nanoTime() - startTime;
}
......@@ -21,7 +28,9 @@ public class GameTimer {
}
public void setTimeBudgetMilliseconds(long budget) {
if(timeSet) throw new IllegalAccessError("You shouldn't try to set the time budget now");
timeBudget = (long) (budget * 1.0E6);
timeSet = true;
}
public long remainingTimeMilliseconds() {
......
......@@ -9,11 +9,15 @@ import battle.SimpleBattle;
*/
public class PiersMCTS implements BattleController {
public PiersMCTS() {
MCTSNode.setAllActions();
}
@Override
public Action getAction(SimpleBattle gameStateCopy, int playerId) {
MCTSNode root = new MCTSNode(2.0, playerId);
GameTimer timer = new GameTimer();
timer.setTimeBudgetMilliseconds(100);
timer.setTimeBudgetMilliseconds(40);
while (timer.remainingTimePercent() > 10) {
MCTSNode travel = root.select(gameStateCopy, 3);
double[] results = travel.rollout(gameStateCopy);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment