Added:
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/Prediction.java
Modified:
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/BetAction.java
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/CallAction.java
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/CheckAction.java
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/FoldAction.java
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/RaiseAction.java
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/SearchBotAction.java
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/mcts/MCTSBot.java
/trunk/ai/bots/src/main/java/org/cspoker/ai/opponentmodels/OpponentModel.java
/trunk/ai/bots/src/main/java/org/cspoker/ai/opponentmodels/simple/HistogramModel.java
/trunk/ai/experiments/src/main/java/org/cspoker/ai/bots/BotRunner.java
/trunk/ai/experiments/src/main/java/org/cspoker/ai/bots/RunHumanVsBot.java
/trunk/ai/opponentmodels/prolog/src/main/java/org/cspoker/ai/opponentmodels/prolog/cafe/PrologCafeModel.java
/trunk/ai/opponentmodels/prolog/src/main/java/org/cspoker/ai/opponentmodels/prolog/redundant/RedundantModel.java
/trunk/ai/opponentmodels/prolog/src/main/java/org/cspoker/ai/opponentmodels/prolog/tuprolog/TuPrologModel.java
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ActionTrackingVisitor.java
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/PlayerTrackingVisitor.java
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/WekaLearningModel.java
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/WekaRegressionModel.java
/trunk/client/common/src/main/java/org/cspoker/client/common/gamestate/modifiers/NewPocketCardsState.java
=======================================
--- /dev/null
+++
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/Prediction.java
Fri Aug 6 01:01:02 2010
@@ -0,0 +1,50 @@
+package org.cspoker.ai.opponentmodels.weka;
+
+import org.cspoker.ai.bots.bot.gametree.action.SearchBotAction;
+
+public class Prediction {
+
+ private SearchBotAction action;
+ private double probActual;
+ private double probHypothesis;
+
+ public Prediction(SearchBotAction action, double probActual, double
probHypothesis) {
+ if (!checkProbability(probActual))
+ throw new IllegalArgumentException("Incorrect probability of actual
action => " + probActual);
+ if (!checkProbability(probHypothesis))
+ throw new IllegalArgumentException("Incorrect probability of hypothesis
action => " + probHypothesis);
+
+ this.action = action;
+ this.probActual = probActual;
+ this.probHypothesis = probHypothesis;
+ }
+
+ private boolean checkProbability(double prob) {
+ return (prob >= 0.0 && prob <= 1.0);
+ }
+
+ public SearchBotAction getAction() {
+ return action;
+ }
+
+ public double getTruePositive() {
+ return Math.min(probActual, probHypothesis);
+ }
+
+ public double getTrueNegative() {
+ return Math.min(1-probActual, 1-probHypothesis);
+ }
+
+ public double getFalsePositive() {
+ return Math.max(0, (1-probActual) - getTrueNegative());
+ }
+
+ public double getFalseNegative() {
+ return Math.max(0, probActual - getTruePositive());
+ }
+
+ @Override
+ public String toString() {
+ return action + " with probability " + probHypothesis;
+ }
+}
=======================================
---
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/BetAction.java
Tue Mar 9 06:36:20 2010
+++
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/BetAction.java
Fri Aug 6 01:01:02 2010
@@ -46,7 +46,7 @@
}
@Override
- public GameState getStateAfterAction() {
+ public GameState getUnwrappedStateAfterAction() {
GameState betState;
int stack = gameState.getPlayer(actor).getStack();
if (stack == amount) {
@@ -54,6 +54,12 @@
} else if (stack > amount) {
betState = new BetState(gameState, new BetEvent(actor, amount));
} else throw new IllegalStateException("Can't bet amount: "+amount+",
with stack: " + stack);
+ return betState;
+ }
+
+ @Override
+ public GameState getStateAfterAction() {
+ GameState betState = getUnwrappedStateAfterAction();
PlayerState nextToAct = betState.getNextActivePlayerAfter(actor);
if (nextToAct != null) {
return new NextPlayerState(betState, new NextPlayerEvent(nextToAct
@@ -70,5 +76,4 @@
return "Bet " + Util.parseDollars(amount);
}
}
-
-}
+}
=======================================
---
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/CallAction.java
Wed Sep 9 06:14:58 2009
+++
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/CallAction.java
Fri Aug 6 01:01:02 2010
@@ -42,6 +42,22 @@
throws RemoteException, IllegalActionException {
context.checkOrCall();
}
+
+ @Override
+ public GameState getUnwrappedStateAfterAction() {
+ PlayerState actorState = gameState.getPlayer(actor);
+ int largestBet = gameState.getLargestBet();
+ int stack = actorState.getStack();
+ int bet = actorState.getBet();
+
+ GameState state;
+ if (stack <= largestBet - bet) {
+ state = new AllInState(gameState, new AllInEvent(actor, stack));
+ } else {
+ state = new CallState(gameState, new CallEvent(actor, largestBet -
bet));
+ }
+ return state;
+ }
@Override
public GameState getStateAfterAction() throws GameEndedException {
@@ -55,12 +71,10 @@
break forloop;
}
}
-
- PlayerState actorState = gameState.getPlayer(actor);
+
+ GameState state = getUnwrappedStateAfterAction();
int largestBet = gameState.getLargestBet();
- int stack = actorState.getStack();
- int bet = actorState.getBet();
-
+
// what if small or big blind all-in?
if (roundEnds
&& gameState.getRound().equals(Round.PREFLOP)
@@ -69,13 +83,7 @@
.getBigBlind()) {
roundEnds = false;
}
-
- GameState state;
- if (stack <= largestBet - bet) {
- state = new AllInState(gameState, new AllInEvent(actor, stack));
- } else {
- state = new CallState(gameState, new CallEvent(actor, largestBet -
bet));
- }
+
if (roundEnds) {
return getNewRoundState(state);
} else {
=======================================
---
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/CheckAction.java
Wed Sep 9 06:14:58 2009
+++
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/CheckAction.java
Fri Aug 6 01:01:02 2010
@@ -40,6 +40,11 @@
context.checkOrCall();
}
+ @Override
+ public GameState getUnwrappedStateAfterAction() {
+ return new CheckState(gameState, new CheckEvent(actor));
+ }
+
@Override
public GameState getStateAfterAction() throws GameEndedException {
PlayerState nextToAct = gameState.getNextActivePlayerAfter(actor);
@@ -50,7 +55,7 @@
&& gameState.getLargestBet() <= gameState
.getTableConfiguration().getBigBlind();
- CheckState checkState = new CheckState(gameState, new CheckEvent(actor));
+ GameState checkState = getUnwrappedStateAfterAction();
if (!newRound) {
return new NextPlayerState(checkState, new NextPlayerEvent(
nextToAct.getPlayerId()));
@@ -62,5 +67,4 @@
public String toString() {
return "Check";
}
-
-}
+}
=======================================
---
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/FoldAction.java
Wed Sep 9 06:14:58 2009
+++
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/FoldAction.java
Fri Aug 6 01:01:02 2010
@@ -40,6 +40,11 @@
throws RemoteException, IllegalActionException {
context.fold();
}
+
+ @Override
+ public GameState getUnwrappedStateAfterAction() {
+ return new FoldState(gameState, new FoldEvent(actor));
+ }
@Override
public GameState getStateAfterAction() throws GameEndedException,
@@ -79,7 +84,7 @@
roundEnds = false;
}
- FoldState foldState = new FoldState(gameState, new FoldEvent(actor));
+ GameState foldState = getUnwrappedStateAfterAction();
if (!roundEnds) {
return new NextPlayerState(foldState, new NextPlayerEvent(foldState
=======================================
---
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/RaiseAction.java
Sat Sep 5 02:01:37 2009
+++
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/RaiseAction.java
Fri Aug 6 01:01:02 2010
@@ -46,7 +46,7 @@
}
@Override
- public GameState getStateAfterAction() {
+ public GameState getUnwrappedStateAfterAction() {
PlayerState actorState = gameState.getPlayer(actor);
int stack = actorState.getStack();
int oldBet = actorState.getBet();
@@ -60,6 +60,12 @@
} else {
raiseState = new RaiseState(gameState, new RaiseEvent(actor, amount,
movedAmount));
}
+ return raiseState;
+ }
+
+ @Override
+ public GameState getStateAfterAction() {
+ GameState raiseState = getUnwrappedStateAfterAction();
return new NextPlayerState(raiseState, new NextPlayerEvent(raiseState
.getNextActivePlayerAfter(actor).getPlayerId()));
}
=======================================
---
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/SearchBotAction.java
Mon Mar 15 05:15:17 2010
+++
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/action/SearchBotAction.java
Fri Aug 6 01:01:02 2010
@@ -47,6 +47,8 @@
public abstract void perform(RemoteHoldemPlayerContext context)
throws RemoteException, IllegalActionException;
+ public abstract GameState getUnwrappedStateAfterAction();
+
public abstract GameState getStateAfterAction() throws GameEndedException,
DefaultWinnerException;
=======================================
---
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/mcts/MCTSBot.java
Mon Jun 14 18:22:02 2010
+++
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/gametree/mcts/MCTSBot.java
Fri Aug 6 01:01:02 2010
@@ -20,18 +20,25 @@
import org.apache.log4j.Logger;
import org.cspoker.ai.bots.bot.AbstractBot;
+import org.cspoker.ai.bots.bot.gametree.action.DefaultWinnerException;
+import org.cspoker.ai.bots.bot.gametree.action.GameEndedException;
import org.cspoker.ai.bots.bot.gametree.action.SearchBotAction;
import org.cspoker.ai.bots.bot.gametree.mcts.listeners.MCTSListener;
import org.cspoker.ai.bots.bot.gametree.mcts.nodes.Config;
import org.cspoker.ai.bots.bot.gametree.mcts.nodes.INode;
+import org.cspoker.ai.bots.bot.gametree.mcts.nodes.InnerNode;
import org.cspoker.ai.bots.bot.gametree.mcts.nodes.RootNode;
import org.cspoker.ai.bots.listener.BotListener;
import org.cspoker.client.common.SmartLobbyContext;
+import org.cspoker.client.common.gamestate.AbstractGameState;
+import org.cspoker.client.common.gamestate.ForwardingGameState;
import org.cspoker.client.common.gamestate.GameState;
import org.cspoker.common.api.shared.exception.IllegalActionException;
import org.cspoker.common.elements.player.PlayerId;
import org.cspoker.common.elements.table.TableId;
+import com.google.common.collect.ImmutableList;
+
//import org.cspoker.common.elements.table.Round;
public class MCTSBot extends AbstractBot {
@@ -99,7 +106,21 @@
iterate(root);
iterate(root);
}while(System.currentTimeMillis()<endTime);
- SearchBotAction action =
root.selectChild(config.getMoveSelectionStrategy()).getLastAction().getAction();
+ INode node = root.selectChild(config.getMoveSelectionStrategy());
+ config.getModel().setChosenNode(node);
+// try {
+// ImmutableList<INode> children = ((InnerNode) node).getChildren();
+// for (INode n: children) {
+// String str = " <last action> ";
+// str = "" +
n.getLastAction().getAction().getUnwrappedStateAfterAction().getClass();
+// System.out.println("Child " + str
+// + " with action " + n.getLastAction().getAction() + " with
probability " +
+// n.getLastAction().getProbability());
+// }
+// } catch (ClassCastException e) {
+// System.out.println("-------------\nNO CLASS CAST\n-------------"); //
do nothing
+// }
+ SearchBotAction action = node.getLastAction().getAction();
if(logger.isInfoEnabled())
logger.info("Stopped MCTS after "+root.getNbSamples()+" samples and
choosing "+action);
@@ -110,7 +131,7 @@
// if (tableContext.getGameState().getRound() == Round.FLOP)
// System.out.print(root.getNbSamples());
// System.out.print("\t");
-// if (tableContext.getGameState().getRound() == Round.TURN)
+// if (tableContext.getGameState().getRound() == Round.TURN)=
// System.out.print(root.getNbSamples());
// System.out.print("\t");
// if (tableContext.getGameState().getRound() == Round.FINAL)
=======================================
---
/trunk/ai/bots/src/main/java/org/cspoker/ai/opponentmodels/OpponentModel.java
Mon Jun 14 18:22:02 2010
+++
/trunk/ai/bots/src/main/java/org/cspoker/ai/opponentmodels/OpponentModel.java
Fri Aug 6 01:01:02 2010
@@ -15,6 +15,7 @@
*/
package org.cspoker.ai.opponentmodels;
+import org.cspoker.ai.bots.bot.gametree.mcts.nodes.INode;
import org.cspoker.client.common.gamestate.GameState;
import org.cspoker.common.elements.player.PlayerId;
import org.cspoker.common.util.Pair;
@@ -35,6 +36,10 @@
GameState gameState, PlayerId actor);
double[] getShowdownProbabilities(GameState gameState, PlayerId actor)
throws UnsupportedOperationException;
+
+ void setChosenNode(INode node);
+
+ INode getChosenNode();
/**
* Assume the given game state permanently.
@@ -51,6 +56,11 @@
*/
void forgetLastAssumption();
+ /**
+ * Get id of bot
+ */
+ PlayerId getBotId();
+
// /**
// * Return a clone of opponentmodel
// */
=======================================
---
/trunk/ai/bots/src/main/java/org/cspoker/ai/opponentmodels/simple/HistogramModel.java
Mon Jun 14 18:22:02 2010
+++
/trunk/ai/bots/src/main/java/org/cspoker/ai/opponentmodels/simple/HistogramModel.java
Fri Aug 6 01:01:02 2010
@@ -19,6 +19,7 @@
import net.jcip.annotations.NotThreadSafe;
+import org.cspoker.ai.bots.bot.gametree.mcts.nodes.INode;
import org.cspoker.ai.opponentmodels.OpponentModel;
import org.cspoker.client.common.gamestate.DetailedHoldemTableState;
import org.cspoker.client.common.gamestate.GameState;
@@ -290,5 +291,20 @@
public void visitConfigChangeState(ConfigChangeState configChangeState) {
}
+
+ @Override
+ public void setChosenNode(INode node) {
+
+ }
+
+ @Override
+ public INode getChosenNode() {
+ return null;
+ }
+
+ @Override
+ public PlayerId getBotId() {
+ return null;
+ }
}
=======================================
--- /trunk/ai/experiments/src/main/java/org/cspoker/ai/bots/BotRunner.java
Mon Jun 14 18:22:02 2010
+++ /trunk/ai/experiments/src/main/java/org/cspoker/ai/bots/BotRunner.java
Fri Aug 6 01:01:02 2010
@@ -68,9 +68,9 @@
private static final TableConfiguration config = new
TableConfiguration(100,
0, false, true, true,0);
- public static final int nbGamesPerConfrontation = 300;
- public static final int reportInterval = 1;
- public final int nbExperiments = 1;
+ public static final int nbGamesPerConfrontation = 1000;
+ public static final int reportInterval = 25;
+ public final int nbExperiments = 3;
public static int currentExperiment = 1;
public int nbPlayersPerGame;
@@ -104,9 +104,10 @@
private final String expName;
private final RemoteCSPokerServer cspokerServer;
- public static void create(RemoteCSPokerServer cspokerServer) {
+ public static void create(RemoteCSPokerServer cspokerServer) {
+ kullbackLeibler = new KullbackLeiblerListener(reportInterval);
// new BotRunner(cspokerServer, "bucketSampler0.01VsRulebots");
- new BotRunner(cspokerServer, "testBucket", getBots());
+ new BotRunner(cspokerServer, "test", getBots());
}
public static BotFactory[] getBots() {
@@ -121,19 +122,19 @@
WekaOptions configNoPersist = new WekaOptions();
configNoPersist.setUseOnlineLearning(false);
WekaOptions configPersist = new WekaOptions();
- configPersist.setContinuousLearning(true);
- configPersist.setModelCreationTreshold(1000);
+ configPersist.setContinuousLearning(false);
+ configPersist.setModelCreationTreshold(100000);
+ configPersist.setContinueAfterCreation(false);
// configPersist.setContinueAfterCreation(true);
Sampler s = new BucketSampler(0.01);
// Sampler s = new StochasticUniversalSampler(9);
// Sampler s = new RouletteWheelSampler(9);
// Sampler s = new RandomSampler(9);
- kullbackLeibler = new KullbackLeiblerListener(reportInterval);
return new BotFactory[] {
-// new CallBotFactory("CallBot"),
- new CardBotFactory("CardBot"),
-// new HandBotFactory("HandBot"),
+// new CallBotFactory("CallBot"), // 62% accuracy
+// new CardBotFactory("CardBot"), // 62% accuracy
+// new HandBotFactory("HandBot"), // 41% accuracy
// new FixedSampleMCTSBotFactory("MCTSBot",
//
WekaRegressionModelFactory.createForZip("org/cspoker/ai/opponentmodels/weka/models/model1.zip",
// configNoPersist),
@@ -147,20 +148,9 @@
// new MaxDistributionPlusBackPropStrategy.Factory()
// ),s,
// 200,500,1000,3000),
-// new MCTSBotFactory("MCTSBot",
-// WekaRegressionModelFactory.createForZip(
-// "org/cspoker/ai/opponentmodels/weka/models/model1.zip",
configNoPersist),
-// new SamplingToFunctionSelector(50,new UCTSelector(2000)),
-// new SamplingSelector(),
-// new MaxValueSelector(),
-// new MCTSShowdownRollOutNode.Factory(),
-// new SampleWeightedBackPropStrategy.Factory(),
-// s,
-// 500
-// ),
- new MCTSBotFactory("MCTSBot",
+ new MCTSBotFactory("MCTSBot NO LEARNING",
WekaRegressionModelFactory.createForZip(
- "org/cspoker/ai/opponentmodels/weka/models/model1.zip",
configPersist, kullbackLeibler),
+ "org/cspoker/ai/opponentmodels/weka/models/model1.zip",
configNoPersist),
new SamplingToFunctionSelector(50,new UCTSelector(2000)),
new SamplingSelector(),
new MaxValueSelector(),
@@ -169,10 +159,21 @@
s,
250
),
-// new SearchBotFactory(
+ new MCTSBotFactory("MCTSBot",
+ WekaRegressionModelFactory.createForZip(
+ "org/cspoker/ai/opponentmodels/weka/models/model1.zip",
configPersist/*, kullbackLeibler*/),
+ new SamplingToFunctionSelector(50,new UCTSelector(20000)),
+ new SamplingSelector(),
+ new MaxValueSelector(),
+ new MCTSShowdownRollOutNode.Factory(),
+ new SampleWeightedBackPropStrategy.Factory(),
+ s,
+ 250
+ ),
+// new SearchBotFactory( // 42,5% accuracy
//
WekaRegressionModelFactory.createForZip("org/cspoker/ai/opponentmodels/weka/models/model1.zip",
configNoPersist),
// new ShowdownRolloutNode.Factory(new
DistributionRollout4.Factory()), s,
-// 200, 600, 1000, 3000, 0.0, false, true
+// 200, 400, 1000, 3000, 0.0, false, true
// )
// new MCTSBotFactory(
// "MCTS Bot",
@@ -306,7 +307,7 @@
bot[0] = botFactories[botIndex[0]].createBot(botIDs[botIndex[0]],
tableId,
botLobbies[botIndex[0]], buyIn, executor,
- new ReSitInBotListener(this), /*csvLogger, speedMonitor,*/
gameLimiter, kullbackLeibler);
+ new ReSitInBotListener(this), csvLogger, /*speedMonitor,*/
gameLimiter, kullbackLeibler);
bot[0].start();
for (int i = 1; i < nbPlayersPerGame; i++) {
bot[i] = botFactories[botIndex[i]].createBot(botIDs[botIndex[i]],
@@ -327,6 +328,7 @@
logger.info("Experiment " + expName + "-" + (currentExperiment - 1)
+ " successfully ended!");
if (currentExperiment <= nbExperiments) {
+ this.botFactories = getBots();
prepareBots();
iterateBots();
} else {
=======================================
---
/trunk/ai/experiments/src/main/java/org/cspoker/ai/bots/RunHumanVsBot.java
Mon Jun 14 18:22:02 2010
+++
/trunk/ai/experiments/src/main/java/org/cspoker/ai/bots/RunHumanVsBot.java
Fri Aug 6 01:01:02 2010
@@ -147,8 +147,8 @@
BotFactory botFactory;
try {
WekaOptions configPersist = new WekaOptions();
- configPersist.setContinuousLearning(true);
- configPersist.setModelCreationTreshold(1);
+ configPersist.setContinuousLearning(false);
+ configPersist.setModelCreationTreshold(100);
botFactory = new MCTSBotFactory("MCTSBot",
WekaRegressionModelFactory.createForZip(
"org/cspoker/ai/opponentmodels/weka/models/model1.zip",
configPersist/*, kullbackLeibler*/),
=======================================
---
/trunk/ai/opponentmodels/prolog/src/main/java/org/cspoker/ai/opponentmodels/prolog/cafe/PrologCafeModel.java
Fri Aug 14 07:58:03 2009
+++
/trunk/ai/opponentmodels/prolog/src/main/java/org/cspoker/ai/opponentmodels/prolog/cafe/PrologCafeModel.java
Fri Aug 6 01:01:02 2010
@@ -28,6 +28,7 @@
import jp.ac.kobe_u.cs.prolog.lang.VariableTerm;
import org.apache.log4j.Logger;
+import org.cspoker.ai.bots.bot.gametree.mcts.nodes.INode;
import org.cspoker.ai.opponentmodels.prolog.AbstractPrologModel;
import org.cspoker.ai.opponentmodels.prolog.ToPrologTermVisitor;
import org.cspoker.common.elements.player.PlayerId;
@@ -110,4 +111,19 @@
}
return (Double) p.toJava();
}
-}
+
+ @Override
+ public void setChosenNode(INode node) {
+
+ }
+
+ @Override
+ public INode getChosenNode() {
+ return null;
+ }
+
+ @Override
+ public PlayerId getBotId() {
+ return null;
+ }
+}
=======================================
---
/trunk/ai/opponentmodels/prolog/src/main/java/org/cspoker/ai/opponentmodels/prolog/redundant/RedundantModel.java
Thu Sep 17 15:34:17 2009
+++
/trunk/ai/opponentmodels/prolog/src/main/java/org/cspoker/ai/opponentmodels/prolog/redundant/RedundantModel.java
Fri Aug 6 01:01:02 2010
@@ -17,6 +17,7 @@
import java.util.Collection;
+import org.cspoker.ai.bots.bot.gametree.mcts.nodes.INode;
import org.cspoker.ai.opponentmodels.OpponentModel;
import org.cspoker.client.common.gamestate.GameState;
import org.cspoker.common.elements.player.PlayerId;
@@ -91,4 +92,19 @@
throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
-}
+
+ @Override
+ public void setChosenNode(INode node) {
+
+ }
+
+ @Override
+ public INode getChosenNode() {
+ return null;
+ }
+
+ @Override
+ public PlayerId getBotId() {
+ return null;
+ }
+}
=======================================
---
/trunk/ai/opponentmodels/prolog/src/main/java/org/cspoker/ai/opponentmodels/prolog/tuprolog/TuPrologModel.java
Fri Aug 14 07:58:03 2009
+++
/trunk/ai/opponentmodels/prolog/src/main/java/org/cspoker/ai/opponentmodels/prolog/tuprolog/TuPrologModel.java
Fri Aug 6 01:01:02 2010
@@ -23,6 +23,7 @@
import jp.ac.kobe_u.cs.prolog.lang.VariableTerm;
import org.apache.log4j.Logger;
+import org.cspoker.ai.bots.bot.gametree.mcts.nodes.INode;
import org.cspoker.ai.opponentmodels.prolog.AbstractPrologModel;
import org.cspoker.ai.opponentmodels.prolog.ToPrologTermVisitor;
import org.cspoker.common.elements.player.PlayerId;
@@ -123,5 +124,20 @@
}
return ((alice.tuprolog.Number) binding).doubleValue();
}
+
+ @Override
+ public void setChosenNode(INode node) {
+
+ }
+
+ @Override
+ public INode getChosenNode() {
+ return null;
+ }
+
+ @Override
+ public PlayerId getBotId() {
+ return null;
+ }
}
=======================================
---
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ActionTrackingVisitor.java
Mon Jun 14 18:22:02 2010
+++
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ActionTrackingVisitor.java
Fri Aug 6 01:01:02 2010
@@ -1,9 +1,11 @@
package org.cspoker.ai.opponentmodels.weka;
import java.io.IOException;
+import java.util.HashMap;
import org.apache.log4j.Logger;
import org.cspoker.client.common.gamestate.DetailedHoldemTableState;
+import org.cspoker.client.common.gamestate.GameState;
import org.cspoker.client.common.gamestate.modifiers.AllInState;
import org.cspoker.client.common.gamestate.modifiers.BetState;
import org.cspoker.client.common.gamestate.modifiers.BlindState;
@@ -27,163 +29,367 @@
import org.cspoker.common.elements.cards.Card;
import org.cspoker.common.elements.player.PlayerId;
import org.cspoker.common.elements.table.Round;
-
+import org.cspoker.common.util.Util;
+
+import org.cspoker.ai.bots.bot.gametree.action.BetAction;
+import org.cspoker.ai.bots.bot.gametree.action.CallAction;
+import org.cspoker.ai.bots.bot.gametree.action.CheckAction;
+import org.cspoker.ai.bots.bot.gametree.action.FoldAction;
+import org.cspoker.ai.bots.bot.gametree.action.RaiseAction;
+import org.cspoker.ai.bots.bot.gametree.mcts.nodes.INode;
+import org.cspoker.ai.bots.bot.gametree.mcts.nodes.InnerNode;
+import org.cspoker.ai.opponentmodels.OpponentModel;
import org.cspoker.ai.opponentmodels.weka.ARFFPropositionalizer;
import org.cspoker.ai.opponentmodels.weka.PlayerTrackingVisitor;
+import com.google.common.collect.ImmutableList;
+
/**
* The ActionTrackingVisitor currently is used to observe the game
* and delegate important states to an {@link ARFFPropositionalizer}<br>
- * <br>
- * TODO: this classes extend {@link PlayerTrackingVisitor} though I think
it doesn't
- * really uses much of its functions (anymore). We should directly
- * implement GameVisitor ?
- *
*/
public class ActionTrackingVisitor extends PlayerTrackingVisitor {
private final static Logger logger =
Logger.getLogger(ARFFPropositionalizer.class);
-
- public ActionTrackingVisitor(PlayerId bot) {
+
+ double truePositive = 0.0;
+ double trueNegative = 0.0;
+ double falsePositive = 0.0;
+ double falseNegative = 0.0;
+
+ public ActionTrackingVisitor(OpponentModel opponentModel, PlayerId bot) {
+ super(opponentModel);
try {
this.propz = new ARFFPropositionalizer(bot);
} catch (IOException e) {
e.printStackTrace();
}
}
-
+
public ARFFPropositionalizer getPropz() {
return (ARFFPropositionalizer) this.propz;
}
-
- @Override
- public void visitAllInState(AllInState allInState) {
- logger.trace("(" +
allInState.getPlayer(allInState.getNextToAct()).getName() + ")
AllInState: " + allInState.getRound());
- propz.signalAllIn(allInState.getEvent().getPlayerId(),
allInState.getEvent().getMovedAmount());
- }
-
- @Override
- public void visitBetState(BetState betState) {
- logger.trace("(" + betState.getPlayer(betState.getNextToAct()).getName()
+ ") BetState: " + betState.getEvent().getAmount());
- propz.signalBet(false, betState.getEvent().getPlayerId(),
betState.getEvent().getAmount());
- }
-
- @Override
- public void visitCallState(CallState callState) {
- logger.trace("(" +
callState.getPlayer(callState.getNextToAct()).getName() + ") CallState");
- propz.signalCall(false, callState.getEvent().getPlayerId());
- }
-
- @Override
- public void visitCheckState(CheckState checkState) {
- logger.trace("(" +
checkState.getPlayer(checkState.getNextToAct()).getName() + ") CheckState");
- propz.signalCheck(checkState.getEvent().getPlayerId());
- }
-
- @Override
- public void visitFoldState(FoldState foldState) {
- logger.trace("(" +
foldState.getPlayer(foldState.getNextToAct()).getName() + ") FoldState");
- propz.signalFold(foldState.getEvent().getPlayerId());
- }
-
- @Override
- public void visitInitialGameState(DetailedHoldemTableState
initialGameState) {
-
- }
-
- @Override
- public void visitJoinTableState(JoinTableState joinTableState) {
-
- }
-
- @Override
- public void visitLeaveTableState(LeaveTableState leaveTableState) {
-
- }
-
- @Override
- public void visitNewCommunityCardsState(NewCommunityCardsState
newCommunityCardsState) {
- logger.trace("NewCommunityCardsState: " +
newCommunityCardsState.getRound() + " ");
-
- logger.trace(" " + newCommunityCardsState.getCommunityCards());
- propz.signalCommunityCards(newCommunityCardsState.getCommunityCards());
- }
-
- @Override
- public void visitNewDealState(NewDealState newDealState) {
- logger.trace("(" +
newDealState.getPlayer(newDealState.getDealer()).getName() + ")
NewDealState");
- propz.signalBBAmount(newDealState.getTableConfiguration().getBigBlind());
- propz.signalNewGame();
- for (PlayerState player : newDealState.getAllSeatedPlayers()) {
- propz.signalSeatedPlayer(player.getStack(), player.getPlayerId());
- }
- }
-
- @Override
- public void visitNewPocketCardsState(NewPocketCardsState
newPocketCardsState) {
-
- }
-
+
+ private InnerNode getNode(GameState state) {
+ try {
+ return (InnerNode) parentOpponentModel.getChosenNode();
+ } catch (ClassCastException e) {
+// System.out.println("-------------\nNO CLASS CAST " +
state.getLastEvent() + "\n-------------");
+ // do nothing
+ return null;
+ }
+ }
+
+ public void printAccuracy() {
+ System.out.println(" Accuracy : " +
+ (trueNegative + truePositive) /
+ (trueNegative + truePositive + falseNegative + falsePositive));
+ }
+
+ private Prediction getProbability(GameState gameState) {
+ return getProbability(gameState, 0);
+ }
+
+ /**
+ * To calculate the accuracy of the opponentmodel we need the
probabilities
+ * of considered actions of opponents when the {@link MCTSBot} calculates
+ * the best action for him to take. For this we use the {@link INode} that
+ * contains the action made by the bot. If it is an {@link InnerNode} the
+ * children contain the probabilities of actions the opponent could make.
+ * Probalities of raises are grouped to give a probability for the action
+ * Raise. To consider consecutive actions by opponents we adjust the
+ * {@link INode} to become the correct child, which is the actual action
+ * made by the opponent. In case of a raise, the raise amongst the
children
+ * nearest to the actual one is chosen.
+ * The probabilities are returned as a {@link Prediction}.
+ *
+ * @param gameState
+ * the {@link GameState} for which we want to calculate the
+ * probability
+ * @param raiseAmount
+ * the bet/raise amount, otherwise 0
+ * @return a {@link Prediction} of the considered action.
+ *
+ * <br>
+ * <br>
+ * TODO: grouping probalities of raises could be improved.
+ */
+ private Prediction getProbability(GameState gameState, double
raiseAmount) {
+ HashMap<Class<?>, Double> probs = new HashMap<Class<?>, Double>();
+ Class<?> cProb = null;
+ RaiseAction raiseAction = null;
+ BetAction betAction = null;
+ InnerNode node = getNode(gameState);
+ if (node != null) {
+// System.out.println(">-----------------------------");
+ ImmutableList<INode> children = node.getChildren();
+ if (children != null) {
+ for (INode n : children) {
+ Class<?> c = n.getLastAction().getAction().getClass();
+ // Same actions are grouped to make one probability (bet/raise)
+ if (!probs.containsKey(c))
+ probs.put(c, n.getLastAction().getProbability());
+ else
+ probs.put(c, n.getLastAction().getProbability() + probs.get(c));
+
+ if (gameState.getClass().equals(
+ n.getLastAction().getAction()
+ .getUnwrappedStateAfterAction().getClass())) {
+ cProb = c;
+ if (raiseAction == null && c.equals(RaiseAction.class))
+ raiseAction = (RaiseAction) n.getLastAction().getAction();
+ else if (betAction == null && c.equals(BetAction.class))
+ betAction = (BetAction) n.getLastAction().getAction();
+ else if (!c.equals(RaiseAction.class) && !c.equals(BetAction.class))
+ parentOpponentModel.setChosenNode(n);
+ }
+
+ // Correct child node is chosen for bet/raise
+ if (cProb != null) {
+ if (raiseAction != null && c.equals(RaiseAction.class)) {
+ RaiseAction newRaiseAction = (RaiseAction)
n.getLastAction().getAction();
+ if (Math.abs(newRaiseAction.amount - raiseAmount) <
+ Math.abs(raiseAction.amount - raiseAmount)) {
+ raiseAction = newRaiseAction;
+ parentOpponentModel.setChosenNode(n);
+ }
+ }
+ else if (betAction != null && c.equals(BetAction.class)) {
+ BetAction newBetAction = (BetAction) n.getLastAction().getAction();
+ if (Math.abs(newBetAction.amount - raiseAmount) <
+ Math.abs(betAction.amount - raiseAmount)) {
+ betAction = newBetAction;
+ parentOpponentModel.setChosenNode(n);
+ }
+ }
+ }
+// System.out.println("State "
+// + gameState.getClass()
+// + " with action "
+// + n.getLastAction().getAction()
+// + "\t with probability "
+// + (double) Math.round(n.getLastAction().getProbability() * 10000)
/ 100
+// + "% and totalProb "
+// + (double) Math.round(probs.get(c) * 10000) / 100 + "%");
+ }
+// System.out.println("> Chosen child with action " +
+// parentOpponentModel.getChosenNode().getLastAction().getAction());
+ }
+// System.out.println("-----------------------------<");
+ }
+
+ return new
Prediction(parentOpponentModel.getChosenNode().getLastAction().getAction(),
+ 1, (cProb == null ? 0.0 : probs.get(cProb)));
+ }
+
+ private void assimilatePrediction(Prediction p) {
+ truePositive += p.getTruePositive();
+ trueNegative += p.getTrueNegative();
+ falsePositive += p.getFalsePositive();
+ falseNegative += p.getFalseNegative();
+ printAccuracy();
+ }
+
@Override
- public void visitNewRoundState(NewRoundState newRoundState) {
- logger.trace("NewRoundState: " + newRoundState.getRound());
- if (newRoundState.getRound() == Round.FLOP) {
- propz.signalFlop();
- } else if (newRoundState.getRound() == Round.TURN) {
- propz.signalTurn();
- } else if (newRoundState.getRound() == Round.FINAL) {
- propz.signalRiver();
- }
- }
-
- @Override
- public void visitNextPlayerState(NextPlayerState nextPlayerState) {
-
- }
-
+ public void visitCallState(CallState callState) {
+ InnerNode node = getNode(callState);
+ if (node != null
&& !callState.getNextToAct().equals(parentOpponentModel.getBotId())) {
+ Prediction p = getProbability(callState);
+ if (p.getAction() instanceof CallAction) {
+ assimilatePrediction(p);
+ logger.trace(getPlayerName(callState) + " " + p);
+ } else
+ System.err.println(getPlayerName(callState) + " CallState != " +
p.getAction());
+ } else {
+ logger.trace(getPlayerName(callState) + " CallState");
+ }
+ propz.signalCall(false, callState.getEvent().getPlayerId());
+ }
+
@Override
public void visitRaiseState(RaiseState raiseState) {
- logger.trace("(" +
raiseState.getPlayer(raiseState.getNextToAct()).getName() + ")
RaiseState: " + raiseState.getLargestBet());
+ InnerNode node = getNode(raiseState);
+ if (node != null
&& !raiseState.getNextToAct().equals(parentOpponentModel.getBotId())) {
+ Prediction p = getProbability(raiseState,raiseState.getLargestBet());
+ if (p.getAction() instanceof RaiseAction) {
+ assimilatePrediction(p);
+ logger.trace(getPlayerName(raiseState) +
+ " Raise " + Util.parseDollars(raiseState.getLargestBet()) +
+ " - with <" + p + ">");
+ } else
+ System.err.println(getPlayerName(raiseState) + " RaiseState: " +
+ Util.parseDollars(raiseState.getLargestBet()) + " != " +
p.getAction());
+ } else {
+ logger.trace(getPlayerName(raiseState) + " RaiseState: " +
Util.parseDollars(raiseState.getLargestBet()));
+ }
propz.signalRaise(false, raiseState.getLastEvent().getPlayerId(),
raiseState.getLargestBet());
}
-
+
@Override
- public void visitShowHandState(ShowHandState showHandState) {
- Card[] cardset = new Card[]{};
- cardset = showHandState.getLastEvent().getShowdownPlayer()
- .getHandCards().toArray(cardset);
- logger.trace("("
- + showHandState.getPlayer(
- showHandState.getLastEvent().getShowdownPlayer()
- .getPlayerId()).getName() + ") ShowHandState: "
- + cardset[0] + ", " + cardset[1]);
-
propz.signalCardShowdown(showHandState.getLastEvent().getShowdownPlayer().getPlayerId(),
cardset[0], cardset[1]);
- }
-
+ public void visitFoldState(FoldState foldState) {
+ InnerNode node = getNode(foldState);
+ if (node != null
&& !foldState.getNextToAct().equals(parentOpponentModel.getBotId())) {
+ Prediction p = getProbability(foldState);
+ if (p.getAction() instanceof FoldAction) {
+ assimilatePrediction(p);
+ logger.trace(getPlayerName(foldState) + " " + p);
+ } else
+ System.err.println(getPlayerName(foldState) + " FoldState" + " != " +
p.getAction());
+ } else {
+ logger.trace(getPlayerName(foldState) + " FoldState");
+ }
+ propz.signalFold(foldState.getEvent().getPlayerId());
+ }
+
@Override
- public void visitSitInState(SitInState sitInState) {
-
- }
-
+ public void visitCheckState(CheckState checkState) {
+ InnerNode node = getNode(checkState);
+ if (node != null
&& !checkState.getNextToAct().equals(parentOpponentModel.getBotId())) {
+ Prediction p = getProbability(checkState);
+ if (p.getAction() instanceof CheckAction) {
+ assimilatePrediction(p);
+ logger.trace(getPlayerName(checkState) + " " + p);
+ } else
+ System.err.println(getPlayerName(checkState) + "CheckState" + " != " +
p.getAction());
+ } else {
+ logger.trace(getPlayerName(checkState) + " CheckState");
+ }
+ propz.signalCheck(checkState.getEvent().getPlayerId());
+ }
+
@Override
- public void visitSitOutState(SitOutState sitOutState) {
-
- }
-
+ public void visitBetState(BetState betState) {
+ InnerNode node = getNode(betState);
+ if (node != null
&& !betState.getNextToAct().equals(parentOpponentModel.getBotId())) {
+ Prediction p = getProbability(betState,
betState.getEvent().getAmount());
+ if (p.getAction() instanceof BetAction) {
+ assimilatePrediction(p);
+ logger.trace(getPlayerName(betState) +
+ " Bet " + Util.parseDollars(betState.getEvent().getAmount()) +
+ " - with <" + p + ">");
+ } else
+ System.err.println(getPlayerName(betState) + " BetState: " +
+ Util.parseDollars(betState.getEvent().getAmount()) + " != " +
p.getAction());
+ } else {
+ logger.trace(getPlayerName(betState) + " BetState: " +
Util.parseDollars(betState.getEvent().getAmount()));
+ }
+ propz.signalBet(false, betState.getEvent().getPlayerId(),
betState.getEvent().getAmount());
+ }
+
@Override
- public void visitBlindState(BlindState blindState) {
- logger.trace("(" +
blindState.getPlayer(blindState.getLastEvent().getPlayerId()).getName()
+ ") BlindState: " + blindState.getRound());
- propz.signalBlind(false, blindState.getLastEvent().getPlayerId(),
blindState.getLastEvent().getAmount());
- }
-
- @Override
- public void visitWinnerState(WinnerState winnerState) {
- logger.trace("(" + winnerState.getLastEvent().getWinners().toArray()[0]
+ ") WinnerState: " + winnerState.getRound());
- }
-
- @Override
- public void visitConfigChangeState(ConfigChangeState configChangeState) {
-
propz.signalBBAmount(configChangeState.getLastEvent().getTableConfig().getBigBlind());
- }
-}
+ public void visitAllInState(AllInState allInState) {
+ InnerNode node = getNode(allInState);
+ if (node != null
&& !allInState.getNextToAct().equals(parentOpponentModel.getBotId())) {
+ Prediction p = getProbability(allInState,
allInState.getEvent().getMovedAmount());
+ if (p.getAction() instanceof BetAction ||
+ p.getAction() instanceof RaiseAction||
+ p.getAction() instanceof CallAction) {
+ assimilatePrediction(p);
+ logger.trace(getPlayerName(allInState) +
+ " All-in " +
Util.parseDollars(allInState.getEvent().getMovedAmount()) +
+ " - with <" + p + ">");
+ } else
+ System.err.println(getPlayerName(allInState) + " AllInState" + " != "
+ p.getAction());
+ } else {
+ logger.trace(getPlayerName(allInState) + " AllInState");
+ }
+ propz.signalAllIn(allInState.getEvent().getPlayerId(),
allInState.getEvent().getMovedAmount());
+ }
+
+// @Override
+// public void visitInitialGameState(DetailedHoldemTableState
initialGameState) {
+//
+// }
+//
+// @Override
+// public void visitJoinTableState(JoinTableState joinTableState) {
+//
+// }
+//
+// @Override
+// public void visitLeaveTableState(LeaveTableState leaveTableState) {
+//
+// }
+//
+// @Override
+// public void visitNewCommunityCardsState(
+// NewCommunityCardsState newCommunityCardsState) {
+// System.out.println("NewCommunityCardsState: " +
newCommunityCardsState.getRound() + " ");
+// System.out.println(" " + newCommunityCardsState.getCommunityCards());
+// propz.signalCommunityCards(newCommunityCardsState.getCommunityCards());
+// }
+//
+// @Override
+// public void visitNewDealState(NewDealState newDealState) {
+// System.out.println("(" +
newDealState.getPlayer(newDealState.getDealer()).getName() + ")
NewDealState");
+//
propz.signalBBAmount(newDealState.getTableConfiguration().getBigBlind());
+// propz.signalNewGame();
+// for (PlayerState player : newDealState.getAllSeatedPlayers()) {
+// propz.signalSeatedPlayer(player.getStack(), player.getPlayerId());
+// }
+// }
+//
+// @Override
+// public void visitNewPocketCardsState(NewPocketCardsState
newPocketCardsState) {
+//// System.out.println("--------------------");
+//// System.out.print("(" + newPocketCardsState.getPlayer().getName()
+ ") Pocket cards: ");
+// newPocketCardsState.getPlayerCards();
+// }
+//
+// @Override
+// public void visitNewRoundState(NewRoundState newRoundState) {
+// System.out.println("NewRoundState: " + newRoundState.getRound());
+// if(newRoundState.getRound()==Round.FLOP){
+// propz.signalFlop();
+// }else if(newRoundState.getRound()==Round.TURN){
+// propz.signalTurn();
+// }else if(newRoundState.getRound()==Round.FINAL){
+// propz.signalRiver();
+// }
+// }
+//
+// @Override
+// public void visitNextPlayerState(NextPlayerState nextPlayerState) {
+//
+// }
+//
+// @Override
+// public void visitShowHandState(ShowHandState showHandState) {
+// Card[] cardset = new Card[]{};
+// cardset = showHandState.getLastEvent().getShowdownPlayer()
+// .getHandCards().toArray(cardset);
+// System.out.println("("
+// + showHandState.getPlayer(
+// showHandState.getLastEvent().getShowdownPlayer()
+// .getPlayerId()).getName() + ") ShowHandState: "
+// + cardset[0] + ", " + cardset[1]);
+//
propz.signalCardShowdown(showHandState.getLastEvent().getShowdownPlayer().getPlayerId(),
cardset[0], cardset[1]);
+// }
+//
+// @Override
+// public void visitSitInState(SitInState sitInState) {
+//
+// }
+//
+// @Override
+// public void visitSitOutState(SitOutState sitOutState) {
+//
+// }
+//
+// @Override
+// public void visitBlindState(BlindState blindState) {
+// System.out.println("(" +
blindState.getPlayer(blindState.getLastEvent().getPlayerId()).getName()
+ ") BlindState: " + blindState.getRound());
+// propz.signalBlind(false, blindState.getLastEvent().getPlayerId(),
blindState.getLastEvent().getAmount());
+// }
+//
+// @Override
+// public void visitWinnerState(WinnerState winnerState) {
+// System.out.println("(" + winnerState.getLastEvent() + ")
WinnerState: " + winnerState.getRound());
+// }
+//
+// @Override
+// public void visitConfigChangeState(ConfigChangeState configChangeState)
{
+//
propz.signalBBAmount(configChangeState.getLastEvent().getTableConfig().getBigBlind());
+// }
+}
=======================================
---
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/PlayerTrackingVisitor.java
Mon Mar 15 05:15:17 2010
+++
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/PlayerTrackingVisitor.java
Fri Aug 6 01:01:02 2010
@@ -16,6 +16,7 @@
package org.cspoker.ai.opponentmodels.weka;
import org.apache.log4j.Logger;
+import org.cspoker.ai.opponentmodels.OpponentModel;
import org.cspoker.client.common.gamestate.DetailedHoldemTableState;
import org.cspoker.client.common.gamestate.GameState;
import org.cspoker.client.common.gamestate.GameStateVisitor;
@@ -39,6 +40,7 @@
import org.cspoker.client.common.gamestate.modifiers.SitOutState;
import org.cspoker.client.common.gamestate.modifiers.WinnerState;
import org.cspoker.client.common.playerstate.PlayerState;
+import org.cspoker.common.elements.cards.Card;
import org.cspoker.common.elements.table.Round;
public class PlayerTrackingVisitor implements GameStateVisitor, Cloneable {
@@ -49,6 +51,16 @@
protected Propositionalizer propz = new Propositionalizer();
+ protected OpponentModel parentOpponentModel;
+
+ public PlayerTrackingVisitor(OpponentModel opponentModel) {
+ this.parentOpponentModel = opponentModel;
+ }
+
+ protected OpponentModel getOpponentModel() {
+ return this.parentOpponentModel;
+ }
+
public void readHistory(GameState gameState) {
try{
gameState.acceptHistoryVisitor(this, previousStartState);
@@ -78,31 +90,46 @@
public Propositionalizer getPropz() {
return propz;
}
+
+ protected String getPlayerName(GameState gameState) {
+ return "(" + gameState.getPlayer(gameState.getNextToAct()).getName()
+ ")";
+ }
@Override
public void visitAllInState(AllInState allInState) {
+ logger.trace("(" +
allInState.getPlayer(allInState.getNextToAct()).getName() + ")
AllInState: " + allInState.getRound());
propz.signalAllIn(allInState.getEvent().getPlayerId(),
allInState.getEvent().getMovedAmount());
}
@Override
public void visitBetState(BetState betState) {
+ logger.trace("(" + betState.getPlayer(betState.getNextToAct()).getName()
+ ") BetState: " + betState.getEvent().getAmount());
propz.signalBet(false, betState.getEvent().getPlayerId(),
betState.getEvent().getAmount());
}
@Override
public void visitCallState(CallState callState) {
+ logger.trace("(" +
callState.getPlayer(callState.getNextToAct()).getName() + ") CallState");
propz.signalCall(false, callState.getEvent().getPlayerId());
}
@Override
public void visitCheckState(CheckState checkState) {
+ logger.trace("(" +
checkState.getPlayer(checkState.getNextToAct()).getName() + ") CheckState");
propz.signalCheck(checkState.getEvent().getPlayerId());
}
@Override
public void visitFoldState(FoldState foldState) {
+ logger.trace("(" +
foldState.getPlayer(foldState.getNextToAct()).getName() + ") FoldState");
propz.signalFold(foldState.getEvent().getPlayerId());
}
+
+ @Override
+ public void visitRaiseState(RaiseState raiseState) {
+ logger.trace("(" +
raiseState.getPlayer(raiseState.getNextToAct()).getName() + ")
RaiseState: " + raiseState.getLargestBet());
+ propz.signalRaise(false, raiseState.getLastEvent().getPlayerId(),
raiseState.getLargestBet());
+ }
@Override
public void visitInitialGameState(DetailedHoldemTableState
initialGameState) {
@@ -122,25 +149,31 @@
@Override
public void visitNewCommunityCardsState(
NewCommunityCardsState newCommunityCardsState) {
-
+ logger.trace("NewCommunityCardsState: " +
newCommunityCardsState.getRound() + " ");
+ logger.trace(" " + newCommunityCardsState.getCommunityCards());
+ propz.signalCommunityCards(newCommunityCardsState.getCommunityCards());
}
@Override
public void visitNewDealState(NewDealState newDealState) {
+ logger.trace("(" +
newDealState.getPlayer(newDealState.getDealer()).getName() + ")
NewDealState");
propz.signalBBAmount(newDealState.getTableConfiguration().getBigBlind());
propz.signalNewGame();
- for(PlayerState player: newDealState.getAllSeatedPlayers()){
+ for (PlayerState player : newDealState.getAllSeatedPlayers()) {
propz.signalSeatedPlayer(player.getStack(), player.getPlayerId());
}
}
@Override
public void visitNewPocketCardsState(NewPocketCardsState
newPocketCardsState) {
-
+// System.out.println("--------------------");
+// System.out.print("(" + newPocketCardsState.getPlayer().getName() + ")
Pocket cards: ");
+ newPocketCardsState.getPlayerCards();
}
@Override
public void visitNewRoundState(NewRoundState newRoundState) {
+ logger.trace("NewRoundState: " + newRoundState.getRound());
if(newRoundState.getRound()==Round.FLOP){
propz.signalFlop();
}else if(newRoundState.getRound()==Round.TURN){
@@ -154,14 +187,18 @@
public void visitNextPlayerState(NextPlayerState nextPlayerState) {
}
-
- @Override
- public void visitRaiseState(RaiseState raiseState) {
- propz.signalRaise(false, raiseState.getLastEvent().getPlayerId(),
raiseState.getLargestBet());
- }
@Override
public void visitShowHandState(ShowHandState showHandState) {
+ Card[] cardset = new Card[]{};
+ cardset = showHandState.getLastEvent().getShowdownPlayer()
+ .getHandCards().toArray(cardset);
+ logger.trace("("
+ + showHandState.getPlayer(
+ showHandState.getLastEvent().getShowdownPlayer()
+ .getPlayerId()).getName() + ") ShowHandState: "
+ + cardset[0] + ", " + cardset[1]);
+
propz.signalCardShowdown(showHandState.getLastEvent().getShowdownPlayer().getPlayerId(),
cardset[0], cardset[1]);
}
@Override
@@ -176,11 +213,13 @@
@Override
public void visitBlindState(BlindState blindState) {
+ logger.trace("(" +
blindState.getPlayer(blindState.getLastEvent().getPlayerId()).getName()
+ ") BlindState: " + blindState.getRound());
propz.signalBlind(false, blindState.getLastEvent().getPlayerId(),
blindState.getLastEvent().getAmount());
}
@Override
public void visitWinnerState(WinnerState winnerState) {
+ logger.trace("(" + winnerState.getLastEvent() + ") WinnerState: " +
winnerState.getRound());
}
@Override
=======================================
---
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/WekaLearningModel.java
Mon Jun 14 18:22:02 2010
+++
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/WekaLearningModel.java
Fri Aug 6 01:01:02 2010
@@ -7,6 +7,7 @@
import java.util.Set;
import org.apache.log4j.Logger;
+import org.cspoker.ai.bots.bot.gametree.mcts.nodes.INode;
import org.cspoker.ai.opponentmodels.OpponentModel;
import org.cspoker.ai.opponentmodels.listener.OpponentModelListener;
import org.cspoker.client.common.gamestate.GameState;
@@ -36,10 +37,11 @@
private final PlayerId bot;
private final OpponentModelListener[] listeners;
+ private INode node;
public WekaLearningModel(PlayerId botId, WekaRegressionModel
defaultModel, WekaOptions config,
OpponentModelListener... listeners) {
- this.permanentVisitor = new PlayerTrackingVisitor();
+ this.permanentVisitor = new PlayerTrackingVisitor(this);
this.visitors.add(permanentVisitor);
this.defaultModel = defaultModel;
this.config = config;
@@ -48,7 +50,7 @@
for (int i = 0; i < listeners.length; i++)
listeners[i].setOpponentModel(this);
if (config.useOnlineLearning()) {
- this.actionTrackingVisitor = new ActionTrackingVisitor(bot);
+ this.actionTrackingVisitor = new ActionTrackingVisitor(this, bot);
}
}
@@ -56,7 +58,7 @@
return config;
}
- // thse methods are used by KullbackLeiblerListener
+ // these methods are used by KullbackLeiblerListener
// TODO: better design (this is messy)
public Map<PlayerId, WekaRegressionModel> getOpponentModels() {
return opponentModels;
@@ -153,5 +155,28 @@
// else System.out.println(")");
return list;
}
+
+ /**
+ * Saves the node with the last move played by {@link MCTSBot}.
+ * Is used to get probabilities of the opponents moves in order
+ * to calculate the accuracy of predictions by the opponentmodel.
+ * @param node INode containing last action by MCTSBot
+ */
+ @Override
+ public void setChosenNode(INode node) {
+ this.node = node;
+ }
+
+ @Override
+ public INode getChosenNode() {
+ return this.node;
+ }
+
+ @Override
+ public PlayerId getBotId() {
+ return bot;
+ }
+
+
}
=======================================
---
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/WekaRegressionModel.java
Mon Jun 14 18:22:02 2010
+++
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/WekaRegressionModel.java
Fri Aug 6 01:01:02 2010
@@ -109,12 +109,8 @@
try {
double prediction;
if ("preflop".equals(props.getRound())) {
- if (preBetModel == null)
- System.out.println(this);
prediction = preBetModel.classifyInstance(instance);
} else {
- if (postBetModel == null)
- System.out.println(this);
prediction = postBetModel.classifyInstance(instance);
}
double prob = Math.min(1, Math.max(0, prediction));
@@ -143,36 +139,24 @@
try {
double probFold;
if (preflop) {
- if (preFoldModel == null)
- System.out.println(this);
probFold = preFoldModel.classifyInstance(instance);
} else {
- if (postFoldModel == null)
- System.out.println(this);
probFold = postFoldModel.classifyInstance(instance);
}
probFold = Math.min(1, Math.max(0, probFold));
double probCall;
if (preflop) {
- if (preCallModel == null)
- System.out.println(this);
probCall = preCallModel.classifyInstance(instance);
} else {
- if (postCallModel == null)
- System.out.println(this);
probCall = postCallModel.classifyInstance(instance);
}
probCall = Math.min(1, Math.max(0, probCall));
double probRaise;
if (preflop) {
- if (preRaiseModel == null)
- System.out.println(this);
probRaise = preRaiseModel.classifyInstance(instance);
} else {
- if (postRaiseModel == null)
- System.out.println(this);
probRaise = postRaiseModel.classifyInstance(instance);
}
probRaise = Math.min(1, Math.max(0, probRaise));
=======================================
---
/trunk/client/common/src/main/java/org/cspoker/client/common/gamestate/modifiers/NewPocketCardsState.java
Mon Sep 7 03:02:47 2009
+++
/trunk/client/common/src/main/java/org/cspoker/client/common/gamestate/modifiers/NewPocketCardsState.java
Fri Aug 6 01:01:02 2010
@@ -77,6 +77,14 @@
};
}
+
+ public EnumSet<Card> getPlayerCards() {
+ return playerState.getCards();
+ }
+
+ public PlayerState getPlayer() {
+ return playerState;
+ }
@Override
public PlayerState getPlayer(PlayerId playerId) {