mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
[mad-ai] Fixed AI. Now plays spells more often.
This commit is contained in:
parent
4bbd8eb1ae
commit
27420f784c
3 changed files with 19 additions and 3 deletions
|
@ -179,10 +179,12 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
SimulationNode2.resetCount();
|
SimulationNode2.resetCount();
|
||||||
root = new SimulationNode2(sim, maxDepth, playerId);
|
root = new SimulationNode2(sim, maxDepth, playerId);
|
||||||
logger.info("simulating actions");
|
logger.info("simulating actions");
|
||||||
|
//int bestScore = addActionsTimed(new FilterAbility());
|
||||||
addActionsTimed(new FilterAbility());
|
addActionsTimed(new FilterAbility());
|
||||||
if (root.children.size() > 0) {
|
if (root.children.size() > 0) {
|
||||||
root = root.children.get(0);
|
root = root.children.get(0);
|
||||||
int bestScore = GameStateEvaluator2.evaluate(playerId, root.getGame());
|
//GameStateEvaluator2.evaluate(playerId, root.getGame());
|
||||||
|
int bestScore = root.getScore();
|
||||||
if (bestScore > currentScore) {
|
if (bestScore > currentScore) {
|
||||||
actions = new LinkedList<Ability>(root.abilities);
|
actions = new LinkedList<Ability>(root.abilities);
|
||||||
combat = root.combat;
|
combat = root.combat;
|
||||||
|
@ -294,7 +296,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
game.getPlayerList().setCurrent(game.getActivePlayerId());
|
game.getPlayerList().setCurrent(game.getActivePlayerId());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addActionsTimed(final FilterAbility filter) {
|
protected Integer addActionsTimed(final FilterAbility filter) {
|
||||||
FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
|
FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
|
||||||
public Integer call() throws Exception
|
public Integer call() throws Exception
|
||||||
{
|
{
|
||||||
|
@ -303,7 +305,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
});
|
});
|
||||||
pool.execute(task);
|
pool.execute(task);
|
||||||
try {
|
try {
|
||||||
task.get(Config2.maxThinkSeconds, TimeUnit.MINUTES);
|
return task.get(Config2.maxThinkSeconds, TimeUnit.MINUTES);
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
logger.info("simulating - timed out");
|
logger.info("simulating - timed out");
|
||||||
task.cancel(true);
|
task.cancel(true);
|
||||||
|
@ -314,6 +316,8 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
task.cancel(true);
|
task.cancel(true);
|
||||||
}
|
}
|
||||||
|
//TODO: timeout handling
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int addActions(SimulationNode2 node, FilterAbility filter, int depth, int alpha, int beta) {
|
protected int addActions(SimulationNode2 node, FilterAbility filter, int depth, int alpha, int beta) {
|
||||||
|
@ -399,6 +403,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
if (val < beta) {
|
if (val < beta) {
|
||||||
beta = val;
|
beta = val;
|
||||||
bestNode = newNode;
|
bestNode = newNode;
|
||||||
|
bestNode.setScore(val);
|
||||||
node.setCombat(newNode.getCombat());
|
node.setCombat(newNode.getCombat());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,6 +411,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
if (val > alpha) {
|
if (val > alpha) {
|
||||||
alpha = val;
|
alpha = val;
|
||||||
bestNode = newNode;
|
bestNode = newNode;
|
||||||
|
bestNode.setScore(val);
|
||||||
node.setCombat(newNode.getCombat());
|
node.setCombat(newNode.getCombat());
|
||||||
if (node.getTargets().size() > 0)
|
if (node.getTargets().size() > 0)
|
||||||
targets = node.getTargets();
|
targets = node.getTargets();
|
||||||
|
@ -426,6 +432,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
if (bestNode != null) {
|
if (bestNode != null) {
|
||||||
node.children.clear();
|
node.children.clear();
|
||||||
node.children.add(bestNode);
|
node.children.add(bestNode);
|
||||||
|
node.setScore(bestNode.getScore());
|
||||||
}
|
}
|
||||||
if (!currentPlayer.getId().equals(playerId)) {
|
if (!currentPlayer.getId().equals(playerId)) {
|
||||||
//logger.info("returning priority beta: " + beta);
|
//logger.info("returning priority beta: " + beta);
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class SimulationNode2 implements Serializable {
|
||||||
|
|
||||||
protected Game game;
|
protected Game game;
|
||||||
protected int gameValue;
|
protected int gameValue;
|
||||||
|
protected int score;
|
||||||
protected List<Ability> abilities;
|
protected List<Ability> abilities;
|
||||||
protected int depth;
|
protected int depth;
|
||||||
protected List<SimulationNode2> children = new ArrayList<SimulationNode2>();
|
protected List<SimulationNode2> children = new ArrayList<SimulationNode2>();
|
||||||
|
@ -124,4 +125,12 @@ public class SimulationNode2 implements Serializable {
|
||||||
public List<String> getChoices() {
|
public List<String> getChoices() {
|
||||||
return this.choices;
|
return this.choices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getScore() {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScore(int score) {
|
||||||
|
this.score = score;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue