diff --git a/src/battle/controllers/Piers/BetterMCTSNode.java b/src/battle/controllers/Piers/BetterMCTSNode.java index 727442d1a496b75fb65d70dd31532b78b566b222..d50424cf3dc9f939cd625bd1c15c513524aa7eb8 100644 --- a/src/battle/controllers/Piers/BetterMCTSNode.java +++ b/src/battle/controllers/Piers/BetterMCTSNode.java @@ -26,13 +26,15 @@ public class BetterMCTSNode { private int numberOfVisits = 1; private double explorationConstant; + private PiersMCTS mcts; - public BetterMCTSNode(double explorationConstant, int playerID) { + public BetterMCTSNode(double explorationConstant, int playerID, PiersMCTS mcts) { this.explorationConstant = explorationConstant; currentDepth = 0; this.playerID = playerID; ourNode = true; children = new BetterMCTSNode[allActions.length]; + this.mcts = mcts; } private BetterMCTSNode(BetterMCTSNode parent, Action ourMoveToThisState) { @@ -43,6 +45,7 @@ public class BetterMCTSNode { this.currentDepth = parent.currentDepth + 1; this.playerID = parent.playerID; this.ourNode = parent.ourNode; + this.mcts = parent.mcts; } public static void setAllActions() { @@ -63,7 +66,7 @@ public class BetterMCTSNode { while (current.currentDepth <= maxDepth) { if (current.fullyExpanded()) { current = current.selectBestChild(); - for (int i = 0; i < PiersMCTS.ACTIONS_PER_MACRO; i++) { + for (int i = 0; i < mcts.ACTIONS_PER_MACRO; i++) { state.update(current.ourMoveToThisState, allActions[random.nextInt(allActions.length)]); } } else { @@ -85,7 +88,7 @@ public class BetterMCTSNode { childToExpand = random.nextInt(allActions.length); } children[childToExpand] = new BetterMCTSNode(this, allActions[childToExpand]); - for (int i = 0; i < PiersMCTS.ACTIONS_PER_MACRO; i++) { + for (int i = 0; i < mcts.ACTIONS_PER_MACRO; i++) { state.update(allActions[childToExpand], allActions[random.nextInt(allActions.length)]); } numberOfChildrenExpanded++; @@ -131,7 +134,7 @@ public class BetterMCTSNode { while (maxDepth > currentRolloutDepth && !state.isGameOver()) { Action first = allActions[random.nextInt(allActions.length)]; Action second = allActions[random.nextInt(allActions.length)]; - for(int i = 0; i < PiersMCTS.ACTIONS_PER_MACRO; i++) { + for (int i = 0; i < mcts.ACTIONS_PER_MACRO; i++) { state.update(first, second); } currentRolloutDepth++; diff --git a/src/battle/controllers/Piers/PiersMCTS.java b/src/battle/controllers/Piers/PiersMCTS.java index 047e477a1325afbbc2667422e47e1314f6377d89..aa4e071849e7cf55f4cc7131c471a015eb86462b 100644 --- a/src/battle/controllers/Piers/PiersMCTS.java +++ b/src/battle/controllers/Piers/PiersMCTS.java @@ -25,19 +25,19 @@ public class PiersMCTS implements BattleController { @Override public Action getAction(SimpleBattle gameStateCopy, int playerId) { GameTimer timer = new GameTimer(); - timer.setTimeBudgetMilliseconds(40); + timer.setTimeBudgetMilliseconds(25); Action action = currentBestAction.getAction(); double distance = gameStateCopy.getShip(0).s.dist(gameStateCopy.getShip(1).s); ACTIONS_PER_MACRO = (distance > DISTANCE_THRESHOLD) ? ACTIONS_PER_MACRO_ENEMY_FAR : ACTIONS_PER_MACRO_ENEMY_CLOSE; - if (root == null) root = new BetterMCTSNode(2.0, playerId); - if (currentBestAction.getTimesUsed() >= ACTIONS_PER_MACRO) root = new BetterMCTSNode(2.0, playerId); + if (root == null) root = new BetterMCTSNode(2.0, playerId, this); + if (currentBestAction.getTimesUsed() >= ACTIONS_PER_MACRO) root = new BetterMCTSNode(2.0, playerId, this); int i = 0; while (timer.remainingTimePercent() > 10) { SimpleBattle copy = gameStateCopy.clone(); - BetterMCTSNode travel = root.select(copy, 6); + BetterMCTSNode travel = root.select(copy, 3); double result = travel.rollout(copy, 10); travel.updateValues(result); i++;