remove custom try/catch with Task, use execute instead of submit for executing runnable so that exceptions are propagated automatically
parent
32f58b7672
commit
f9aaca1488
|
@ -142,9 +142,9 @@ public class MCTSAI implements MagicAI {
|
|||
final int aiLevel = scorePlayer.getAiProfile().getAiLevel();
|
||||
final long START_TIME = System.currentTimeMillis();
|
||||
final long END_TIME = START_TIME + 1000 * aiLevel;
|
||||
final Runnable updateTask = new Task() {
|
||||
final Runnable updateTask = new Runnable() {
|
||||
@Override
|
||||
public void execute() {
|
||||
public void run() {
|
||||
TreeUpdate(this, root, aiGame, executor, queue, END_TIME);
|
||||
}
|
||||
};
|
||||
|
@ -247,7 +247,7 @@ public class MCTSAI implements MagicAI {
|
|||
|
||||
// submit random play to executor
|
||||
if (running) {
|
||||
executor.submit(genSimulationTask(rootGame, path, queue));
|
||||
executor.execute(genSimulationTask(rootGame, path, queue));
|
||||
}
|
||||
|
||||
// virtual loss + game theoretic value propagation
|
||||
|
@ -276,7 +276,7 @@ public class MCTSAI implements MagicAI {
|
|||
|
||||
// end simulations once root is AI win or time is up
|
||||
if (running && root.isAIWin() == false) {
|
||||
executor.submit(updateTask);
|
||||
executor.execute(updateTask);
|
||||
} else {
|
||||
executor.shutdown();
|
||||
}
|
||||
|
|
|
@ -79,9 +79,9 @@ public class MMAB implements MagicAI {
|
|||
workerGame.setFastTarget(true);
|
||||
workerGame.setFastBlocker(true);
|
||||
|
||||
executor.execute(new Task() {
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void execute() {
|
||||
public void run() {
|
||||
final MMABWorker worker=new MMABWorker(
|
||||
Thread.currentThread().getId(),
|
||||
workerGame,
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package magic.ai;
|
||||
|
||||
public abstract class Task implements Runnable {
|
||||
@Override
|
||||
public final void run() {
|
||||
try {
|
||||
execute();
|
||||
} catch (final Throwable ex) {
|
||||
final Thread t = Thread.currentThread();
|
||||
t.getUncaughtExceptionHandler().uncaughtException(t, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void execute();
|
||||
}
|
|
@ -3,7 +3,7 @@ package magic.ai;
|
|||
import magic.model.MagicGame;
|
||||
import magic.model.event.MagicEvent;
|
||||
|
||||
public class VegasWorker extends Task {
|
||||
public class VegasWorker implements Runnable {
|
||||
|
||||
private static final int MAIN_PHASES=6;
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class VegasWorker extends Task {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
public void run() {
|
||||
final long endTime = System.nanoTime() + slice;
|
||||
while (System.nanoTime() < endTime) {
|
||||
final MagicGame game = new MagicGame(sourceGame, sourceGame.getScorePlayer());
|
||||
|
|
Loading…
Reference in New Issue