remove pruneScore to avoid problems with threads

master
melvin 2013-04-05 12:58:22 +08:00
parent 3638a78c3f
commit 6a0f40d22a
2 changed files with 21 additions and 11 deletions

View File

@ -0,0 +1,18 @@
package magic.ai;
class ArtificialPruneScoreRef {
private ArtificialPruneScore pruneScore;
public ArtificialPruneScoreRef(final ArtificialPruneScore pScore) {
pruneScore = pScore;
}
public void update(final int score) {
pruneScore = pruneScore.getPruneScore(score,true);
}
public ArtificialPruneScore get() {
return pruneScore;
}
}

View File

@ -20,7 +20,6 @@ public class MMAB implements MagicAI {
private final boolean LOGGING;
private final boolean CHEAT;
private ArtificialPruneScore pruneScore = new ArtificialMultiPruneScore();
MMAB() {
//default: no logging, no cheats
@ -58,6 +57,7 @@ public class MMAB implements MagicAI {
}
// submit jobs
final ArtificialPruneScoreRef scoreRef = new ArtificialPruneScoreRef(new ArtificialMultiPruneScore());
final ArtificialScoreBoard scoreBoard = new ArtificialScoreBoard();
final ExecutorService executor = Executors.newFixedThreadPool(THREADS);
final List<ArtificialChoiceResults> achoices=new ArrayList<ArtificialChoiceResults>();
@ -81,8 +81,8 @@ public class MMAB implements MagicAI {
scoreBoard,
CHEAT
);
worker.evaluateGame(achoice, getPruneScore(), System.nanoTime() + slice);
updatePruneScore(achoice.aiScore.getScore());
worker.evaluateGame(achoice, scoreRef.get(), System.nanoTime() + slice);
scoreRef.update(achoice.aiScore.getScore());
}
});
}
@ -124,14 +124,6 @@ public class MMAB implements MagicAI {
return sourceGame.map(bestAchoice.choiceResults);
}
private void updatePruneScore(final int score) {
pruneScore = pruneScore.getPruneScore(score,true);
}
private ArtificialPruneScore getPruneScore() {
return pruneScore;
}
class MMABWorker {
private final boolean CHEAT;