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

Added discount factor and changed scoring and added variable macro action...

Added discount factor and changed scoring and added variable macro action length based on closeness of enemy ship but should probably do it based on nearness of any other obstacle
parent 0f5ff745
No related branches found
No related tags found
No related merge requests found
package battle.controllers.Piers;
import asteroids.Action;
import battle.NeuroShip;
import battle.SimpleBattle;
import java.util.Random;
......@@ -116,9 +115,11 @@ public class BetterMCTSNode {
public void updateValues(double value) {
BetterMCTSNode current = this;
double alteredValue = value / 1000;
double discountFactor = 0.95;
while (current.parent != null) {
current.numberOfVisits++;
current.totalValue += alteredValue;
alteredValue *= discountFactor;
current.totalValue += (alteredValue);
current = current.parent;
}
current.totalValue += alteredValue;
......@@ -132,7 +133,10 @@ public class BetterMCTSNode {
Action second = allActions[random.nextInt(allActions.length)];
state.update(first, second);
}
return state.getPoints(playerID) - (100 - state.getMissilesLeft(playerID));
int missilesUsed = 100 - state.getMissilesLeft(playerID);
int ourPoints = state.getPoints(playerID);
int enemyPoints = state.getPoints(playerID == 0 ? 1 : 0);
return (ourPoints - (missilesUsed * 5) - (enemyPoints * 1.5));
}
public Action getBestAction() {
......
......@@ -9,7 +9,10 @@ import battle.SimpleBattle;
*/
public class PiersMCTS implements BattleController {
protected static final int ACTIONS_PER_MACRO = 15;
protected static int ACTIONS_PER_MACRO = 15;
protected static final int ACTIONS_PER_MACRO_ENEMY_CLOSE = 3;
protected static final int ACTIONS_PER_MACRO_ENEMY_FAR = 15;
protected static final double DISTANCE_THRESHOLD = 100;
private MacroAction currentBestAction = new MacroAction(new Action(1, 0, false));
private BetterMCTSNode root;
......@@ -24,14 +27,18 @@ public class PiersMCTS implements BattleController {
GameTimer timer = new GameTimer();
timer.setTimeBudgetMilliseconds(40);
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);
int i = 0;
while (timer.remainingTimePercent() > 10) {
SimpleBattle copy = gameStateCopy.clone();
BetterMCTSNode travel = root.select(copy, 5);
double result = travel.rollout(copy, 50);
BetterMCTSNode travel = root.select(copy, 6);
double result = travel.rollout(copy, 10);
travel.updateValues(result);
i++;
}
......@@ -65,7 +72,7 @@ class MacroAction {
*/
public Action getAction() {
timesUsed++;
return (timesUsed == 1) ? action : nonShootingVersion;
return (timesUsed <= 2) ? action : nonShootingVersion;
}
public int getTimesUsed() {
......
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