Revision: d4f4a29fe76d
Author: thijs
Date: Thu Apr 28 01:55:39 2011
Log: updates to the tree building mechanism
http://code.google.com/p/opentestbed/source/detail?r=d4f4a29fe76d
Revision: 1104682fed2f
Author: thijs
Date: Mon May 2 07:00:38 2011
Log: implemented test with SDR
http://code.google.com/p/opentestbed/source/detail?r=1104682fed2f
==============================================================================
Revision: d4f4a29fe76d
Author: thijs
Date: Thu Apr 28 01:55:39 2011
Log: updates to the tree building mechanism
http://code.google.com/p/opentestbed/source/detail?r=d4f4a29fe76d
Added:
/src/bots/mctsbot/ai/bots/bot/gametree/tls/TLSMeerkatBot.java
Modified:
/src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/AbstractTLSNode.java
/src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/InnerNode.java
/src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/LeafNode.java
/src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/RootNode.java
/src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/TLSTree.java
=======================================
--- /dev/null
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/TLSMeerkatBot.java Thu Apr
28 01:55:39 2011
@@ -0,0 +1,77 @@
+package bots.mctsbot.ai.bots.bot.gametree.tls;
+
+import com.biotools.meerkat.Action;
+import com.biotools.meerkat.Card;
+import com.biotools.meerkat.GameInfo;
+import com.biotools.meerkat.Player;
+import com.biotools.meerkat.util.Preferences;
+
+public class TLSMeerkatBot implements Player {
+
+ @Override
+ public Action getAction() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void holeCards(Card arg0, Card arg1, int arg2) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void init(Preferences arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void actionEvent(int arg0, Action arg1) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dealHoleCardsEvent() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void gameOverEvent() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void gameStartEvent(GameInfo arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void gameStateChanged() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void showdownEvent(int arg0, Card arg1, Card arg2) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void stageEvent(int arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void winEvent(int arg0, double arg1, String arg2) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/AbstractTLSNode.java
Wed Apr 27 09:48:06 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/AbstractTLSNode.java
Thu Apr 28 01:55:39 2011
@@ -4,6 +4,7 @@
import java.util.List;
import bots.mctsbot.ai.bots.bot.gametree.action.SearchBotAction;
+import
bots.mctsbot.ai.bots.bot.gametree.mcts.strategies.backpropagation.BackPropagationStrategy;
import bots.mctsbot.ai.bots.bot.gametree.tls.SimulatedGame;
import
bots.mctsbot.ai.bots.bot.gametree.tls.strategies.selection.SelectionStrategy;
import bots.mctsbot.ai.bots.bot.gametree.tls.tests.Test;
@@ -13,12 +14,17 @@
protected AbstractTLSNode leftChild;
protected AbstractTLSNode rightChild;
+ private final TLSTree tree;
+
+ protected BackPropagationStrategy backPropagationStrategy;
+
private int nbSamples = 0;
- private List<Test> possibleTests = new ArrayList<Test>();
-
- public AbstractTLSNode(AbstractTLSNode parent) {
+ protected List<Test> possibleTests = new ArrayList<Test>();
+
+ public AbstractTLSNode(AbstractTLSNode parent, TLSTree tree) {
this.parent = parent;
+ this.tree = tree;
}
private final AbstractTLSNode parent;
@@ -31,19 +37,23 @@
return rightChild;
}
- public abstract AbstractTLSNode selectChild(SelectionStrategy strategy);
+ public AbstractTLSNode selectChild(SelectionStrategy strategy) {
+ return strategy.select(this);
+ }
public AbstractTLSNode getParent() {
return parent;
}
public void backPropagate(double value, SimulatedGame game) {
- SearchBotAction action = game.pop();
+ SearchBotAction action = game.peek();
if (!isSplit()) {
for (Test test : possibleTests) {
test.updateStats(action, value);
}
}
+ backPropagationStrategy.onBackPropagate(value);
+ this.getParent().backPropagate(value, game);
}
protected boolean isSplit() {
@@ -54,8 +64,8 @@
* For now when a node is split, all information down the tree is lost.
*/
public void split() {
- leftChild = new LeafNode(getParent());
- rightChild = new LeafNode(getParent());
+ leftChild = new LeafNode(getParent(), getTree());
+ rightChild = new LeafNode(getParent(), getTree());
}
public int getNbSamples() {
@@ -63,13 +73,15 @@
}
public double getEVStdDev() {
- // TODO Auto-generated method stub
- return 0;
+ return backPropagationStrategy.getEVStdDev();
}
public double getEV() {
- // TODO Auto-generated method stub
- return 0;
+ return backPropagationStrategy.getEV();
+ }
+
+ public TLSTree getTree() {
+ return tree;
}
}
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/InnerNode.java Wed Apr
27 09:48:06 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/InnerNode.java Thu Apr
28 01:55:39 2011
@@ -1,16 +1,10 @@
package bots.mctsbot.ai.bots.bot.gametree.tls.nodes;
-import
bots.mctsbot.ai.bots.bot.gametree.tls.strategies.selection.SelectionStrategy;
public class InnerNode extends AbstractTLSNode {
- public InnerNode(AbstractTLSNode parent) {
- super(parent);
- }
-
- @Override
- public AbstractTLSNode selectChild(SelectionStrategy strategy) {
- return strategy.select(this);
+ public InnerNode(AbstractTLSNode parent, TLSTree tree) {
+ super(parent, tree);
}
}
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/LeafNode.java Wed Apr
27 09:48:06 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/LeafNode.java Thu Apr
28 01:55:39 2011
@@ -1,16 +1,14 @@
package bots.mctsbot.ai.bots.bot.gametree.tls.nodes;
-
public class LeafNode extends InnerNode {
public TLSTree childTree;
- public LeafNode(AbstractTLSNode parent) {
- super(parent);
+ public LeafNode(AbstractTLSNode parent, TLSTree tree) {
+ super(parent, tree);
}
public void expand() {
-
- }
-
-}
+ childTree = new TLSTree(this.getTree().getPlayer(), this);
+ }
+}
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/RootNode.java Wed Apr
27 09:48:06 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/RootNode.java Thu Apr
28 01:55:39 2011
@@ -1,21 +1,25 @@
package bots.mctsbot.ai.bots.bot.gametree.tls.nodes;
-import
bots.mctsbot.ai.bots.bot.gametree.tls.strategies.selection.SelectionStrategy;
+import bots.mctsbot.ai.bots.bot.gametree.tls.SimulatedGame;
public class RootNode extends AbstractTLSNode {
- public final TLSTree tree;
-
public RootNode(TLSTree tree) {
- super(null);
- this.tree = tree;
- this.leftChild = new LeafNode(this);
+ super(null, tree);
+ this.leftChild = new LeafNode(this, this.getTree());
}
@Override
- public AbstractTLSNode selectChild(SelectionStrategy strategy) {
- // TODO Auto-generated method stub
- return null;
+ public void backPropagate(double value, SimulatedGame game) {
+ if (!this.getTree().isRoot()) {
+ super.backPropagate(value, game);
+ game.pop();
+ }
+ }
+
+ @Override
+ public AbstractTLSNode getParent() {
+ return this.getTree().getParent();
}
}
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/TLSTree.java Wed Apr
27 09:48:06 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/TLSTree.java Thu Apr
28 01:55:39 2011
@@ -5,6 +5,19 @@
public class TLSTree {
public final PlayerId player;
+
+ public PlayerId getPlayer() {
+ return player;
+ }
+
+ public RootNode getRoot() {
+ return root;
+ }
+
+ public LeafNode getParent() {
+ return parent;
+ }
+
public final RootNode root;
public final LeafNode parent;
@@ -13,5 +26,9 @@
this.parent = parent;
root = new RootNode(this);
}
+
+ public boolean isRoot() {
+ return parent == null;
+ }
}
==============================================================================
Revision: 1104682fed2f
Author: thijs
Date: Mon May 2 07:00:38 2011
Log: implemented test with SDR
http://code.google.com/p/opentestbed/source/detail?r=1104682fed2f
Modified:
/src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/AbstractTLSNode.java
/src/bots/mctsbot/ai/bots/bot/gametree/tls/tests/Test.java
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/AbstractTLSNode.java
Thu Apr 28 01:55:39 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/AbstractTLSNode.java
Mon May 2 07:00:38 2011
@@ -75,6 +75,10 @@
public double getEVStdDev() {
return backPropagationStrategy.getEVStdDev();
}
+
+ public double getStdDev() {
+ return backPropagationStrategy.getStdDev();
+ }
public double getEV() {
return backPropagationStrategy.getEV();
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/tests/Test.java Wed Apr 27
09:48:06 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/tests/Test.java Mon May 2
07:00:38 2011
@@ -1,12 +1,58 @@
package bots.mctsbot.ai.bots.bot.gametree.tls.tests;
+import bots.mctsbot.ai.bots.bot.gametree.action.BetAction;
+import bots.mctsbot.ai.bots.bot.gametree.action.CallAction;
+import bots.mctsbot.ai.bots.bot.gametree.action.CheckAction;
+import bots.mctsbot.ai.bots.bot.gametree.action.FoldAction;
+import bots.mctsbot.ai.bots.bot.gametree.action.RaiseAction;
import bots.mctsbot.ai.bots.bot.gametree.action.SearchBotAction;
+import bots.mctsbot.ai.bots.bot.gametree.tls.nodes.AbstractTLSNode;
+import bots.mctsbot.ai.bots.util.RunningStats;
public class Test {
+
+ private static final Class[] line = { FoldAction.class,
CheckAction.class, CallAction.class, BetAction.class, RaiseAction.class };
+ private final SearchBotAction testAction;
+ private final int testIndex;
+
+ private final RunningStats failStats = new RunningStats();
+ private final RunningStats successStats = new RunningStats();
+
+ private final AbstractTLSNode node;
+
+ public Test(SearchBotAction action, AbstractTLSNode node) {
+ this.testAction = action;
+ testIndex = findIndex(action);
+ this.node = node;
+ }
public void updateStats(SearchBotAction action, double value) {
- // TODO Auto-generated method stub
-
+ if (succeeds(action))
+ successStats.add(value);
+ else
+ failStats.add(value);
+ }
+
+ private boolean succeeds(SearchBotAction action) {
+ if (findIndex(action) < testIndex)
+ return false;
+ if (testAction instanceof BetAction && action instanceof BetAction)
+ return ((BetAction) action).amount >= ((BetAction) testAction).amount;
+ if (testAction instanceof RaiseAction && action instanceof RaiseAction)
+ return ((RaiseAction) action).amount >= ((RaiseAction)
testAction).amount;
+ return true;
}
-}
+ private int findIndex(SearchBotAction action) {
+ for (int i = 0; i < line.length; i++) {
+ if (line[i] == action.getClass())
+ return i;
+ }
+ throw new IllegalArgumentException("The runtime class of the argument
does not match any class in the action line");
+ }
+
+ public double getSDR() {
+ return node.getStdDev() - failStats.getNbSamples() / node.getNbSamples()
* failStats.getStdDev() - successStats.getNbSamples() / node.getNbSamples()
+ * successStats.getStdDev();
+ }
+}