diff --git a/src/org/ggp/base/player/gamer/statemachine/hu/MCL_thread.java b/src/org/ggp/base/player/gamer/statemachine/hu/MCL_thread.java index 9a682a346..0a0f18c51 100644 --- a/src/org/ggp/base/player/gamer/statemachine/hu/MCL_thread.java +++ b/src/org/ggp/base/player/gamer/statemachine/hu/MCL_thread.java @@ -1,40 +1,66 @@ package org.ggp.base.player.gamer.statemachine.hu; import org.ggp.base.util.statemachine.MachineState; -import org.ggp.base.util.statemachine.Move; import org.ggp.base.util.statemachine.StateMachine; +import org.ggp.base.util.statemachine.exceptions.GoalDefinitionException; +import org.ggp.base.util.statemachine.exceptions.MoveDefinitionException; +import org.ggp.base.util.statemachine.exceptions.TransitionDefinitionException; + public class MCL_thread extends Thread { + Tromboter player; + StateMachine mymachine; + double i; + MachineState state; + boolean run = true; - MCL_thread(int monteScores[], int i,Move ownMove, StateMachine mymachine){ + MCL_thread(double i, StateMachine mymachine, MachineState state, Tromboter player){ super(); - + // initalize parameters - - + this.player = player; + this.mymachine = mymachine; + this.i = i; + this.state = state; } @Override public void run() { - // do - - // run monteZott - - // write monteZott's return value in too the array or determine average - - // while (is enough time || iterated enough) - - //exit run => close thread + int value = 0; + int times = 0; + + while(run){ + + // run monteZott + try { + + value += monteZott(); + times++; + + } catch (Exception e) { + + } + + // write monteZott's return value in too the array or determine average + i = ((double)value)/times; + + } + + //exit run => close thread } - - - private int monteZott(StateMachine mymachine, MachineState state) throws TransitionDefinitionException, MoveDefinitionException, GoalDefinitionException + + + private int monteZott() throws TransitionDefinitionException, MoveDefinitionException, GoalDefinitionException { MachineState finalState = mymachine.performDepthCharge(state, new int[1]); - return mymachine.getGoal(finalState, getRole()); + return mymachine.getGoal(finalState, player.getRole()); } - + + void stopThread(){ + run = false; + } + } diff --git a/src/org/ggp/base/player/gamer/statemachine/hu/Tromboter.java b/src/org/ggp/base/player/gamer/statemachine/hu/Tromboter.java index 260bbfd31..db07072d0 100644 --- a/src/org/ggp/base/player/gamer/statemachine/hu/Tromboter.java +++ b/src/org/ggp/base/player/gamer/statemachine/hu/Tromboter.java @@ -1,8 +1,6 @@ package org.ggp.base.player.gamer.statemachine.hu; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.ggp.base.apps.player.detail.DetailPanel; @@ -11,7 +9,6 @@ import org.ggp.base.player.gamer.exception.GamePreviewException; import org.ggp.base.player.gamer.statemachine.StateMachineGamer; import org.ggp.base.util.game.Game; -import org.ggp.base.util.logging.GamerLogger; import org.ggp.base.util.statemachine.MachineState; import org.ggp.base.util.statemachine.Move; import org.ggp.base.util.statemachine.StateMachine; @@ -76,25 +73,17 @@ public Move stateMachineSelectMove(long timeout) throws TransitionDefinitionExce int i = 0; int depth = 100; - try { - int monteScores[] = new int[mymachine.getLegalJointMoves(getCurrentState()).size()]; - Arrays.fill(monteScores, -1); - for (List ownMove:mymachine.getLegalJointMoves(getCurrentState())){ - // do thread magic here - startMonteThread(monteScores, i, ownMove); - } + Double monteScores[]; + monteScores = new Double[mymachine.getLegalJointMoves(getCurrentState()).size()]; + Arrays.fill(monteScores, -1.0); - boolean allDone = false; - while (!allDone) { - allDone = true; - for (int score:monteScores) { - if (score == -1) { - allDone = false; - } - } - } + MCLThreadVerwalter mclVerwalter = new MCLThreadVerwalter(monteScores, mymachine, this); + + mclVerwalter.start(); + // in nen Thread + /* List nodeScores = new ArrayList(); for (List ownMove:mymachine.getLegalJointMoves(getCurrentState())){ try { @@ -117,13 +106,43 @@ public Move stateMachineSelectMove(long timeout) throws TransitionDefinitionExce e.printStackTrace(); } } - } catch (MoveDefinitionException e) { - e.printStackTrace(); - } + */ + // We get the end time // It is mandatory that stopmyscore){ + myscore = monteScores[j]; + index = j; + } + } + + mclVerwalter.stopMinions(); + mclVerwalter.stopThread(); + + if (moves.size() != 1) { + try { + selection = mymachine.getLegalMoves(getCurrentState(), getRole()).get(index); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + long stop = System.currentTimeMillis(); /** @@ -203,7 +222,7 @@ private int getNodeScore(MachineState state) throws MoveDefinitionException, Goa } return myscore; } - */ + */ private int minimax(StateMachine mymachine, MachineState state, int depth, boolean maximizingPlayer) throws GoalDefinitionException, MoveDefinitionException, TransitionDefinitionException { if (depth == 0 || mymachine.isTerminal(state)) {