From 5bed83db6ff2cec2a3cd4b9a88519aa229f8d1a0 Mon Sep 17 00:00:00 2001 From: Robert Sprunk Date: Mon, 2 Dec 2013 17:13:17 +0100 Subject: [PATCH] min/max node score approach --- .../python/stubs/SamplePythonGamerStub.java | 1 + .../gamer/statemachine/hu/Tromboter.java | 76 +++++++++++++++++-- 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/src/org/ggp/base/player/gamer/python/stubs/SamplePythonGamerStub.java b/src/org/ggp/base/player/gamer/python/stubs/SamplePythonGamerStub.java index 194251a10..9987a1757 100644 --- a/src/org/ggp/base/player/gamer/python/stubs/SamplePythonGamerStub.java +++ b/src/org/ggp/base/player/gamer/python/stubs/SamplePythonGamerStub.java @@ -15,4 +15,5 @@ public final class SamplePythonGamerStub extends PythonGamer protected String getPythonGamerModule() { return "sample_gamer"; } @Override protected String getPythonGamerName() { return "SamplePythonGamer"; } + } \ No newline at end of file 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 d45db5f54..be6ade885 100644 --- a/src/org/ggp/base/player/gamer/statemachine/hu/Tromboter.java +++ b/src/org/ggp/base/player/gamer/statemachine/hu/Tromboter.java @@ -1,5 +1,7 @@ package org.ggp.base.player.gamer.statemachine.hu; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.ggp.base.apps.player.detail.DetailPanel; @@ -8,6 +10,8 @@ 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; import org.ggp.base.util.statemachine.cache.CachedStateMachine; @@ -38,6 +42,7 @@ public Move stateMachineSelectMove(long timeout) throws TransitionDefinitionExce { // We get the current start time long start = System.currentTimeMillis(); + StateMachine mymachine = getStateMachine(); /** * We put in memory the list of legal moves from the @@ -45,13 +50,41 @@ public Move stateMachineSelectMove(long timeout) throws TransitionDefinitionExce * is to return one of these moves. The choice of which * Move to play is the goal of GGP. */ - List moves = getStateMachine().getLegalMoves(getCurrentState(), getRole()); - - // SampleLegalGamer is very simple : it picks the first legal move - Move selection = moves.get(0); + List moves = mymachine.getLegalMoves(getCurrentState(), getRole()); + Move selection = moves.get(moves.size()-1); + + // Log + StringBuilder output = new StringBuilder(); + output.append(getRole()); + output.append("\n"); + GamerLogger.emitToConsole(output.toString()); + + while (true) { + if (System.currentTimeMillis() > timeout - 500) { + break; + } + selection = mymachine.getRandomMove(getCurrentState(), getRole()); + } + + + + /* + for (Move amove:getStateMachine().getLegalMoves(getCurrentState(), getRole()) { + for (Role arole:getStateMachine().getRoles()) { + try { + MachineState finalState = mymachine.performDepthCharge(mymachine.getRandomNextState(theState, getRole(), myMove), depth); + return theMachine.getGoal(finalState, getRole()); + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + } + */ // We get the end time // It is mandatory that stop nodeScores = new ArrayList(); + for (List amove:getStateMachine().getLegalJointMoves(state)) { + //MachineState newstate = getStateMachine().performDepthCharge(getStateMachine().getNextState(state, amove), ); + // TODO: Unterscheidung zwischen Rollen: min/max + try { + nodeScores.add(getMaxNodeScore(getStateMachine().getNextState(state, amove))); + } catch (TransitionDefinitionException e) { + e.printStackTrace(); + } + } + return Collections.max(nodeScores); + } catch (MoveDefinitionException e) { + e.printStackTrace(); + return 0; + } + } + + } \ No newline at end of file