[opentestbed] 2 new revisions pushed by thijs.le...@gmail.com on 2011-05-05 09:18 GMT

10 views
Skip to first unread message

opent...@googlecode.com

unread,
May 5, 2011, 5:19:25 AM5/5/11
to opent...@googlegroups.com
2 new revisions:

Revision: 4997eb1149fa
Author: thijs
Date: Thu May 5 02:17:36 2011
Log: updated metatree structure
http://code.google.com/p/opentestbed/source/detail?r=4997eb1149fa

Revision: 116cccca8f3e
Author: thijs
Date: Thu May 5 02:18:17 2011
Log: updated metatree structure and bot builded
http://code.google.com/p/opentestbed/source/detail?r=116cccca8f3e

==============================================================================
Revision: 4997eb1149fa
Author: thijs
Date: Thu May 5 02:17:36 2011
Log: updated metatree structure
http://code.google.com/p/opentestbed/source/detail?r=4997eb1149fa

Added:
/src/bots/mctsbot/ai/bots/bot/gametree/tls/metatree/TLSTree.java
Deleted:
/src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/TLSTree.java

/src/bots/mctsbot/ai/bots/bot/gametree/tls/strategies/selection/UCTPlusSelector.java
Modified:

/src/bots/mctsbot/ai/bots/bot/gametree/mcts/strategies/backpropagation/SampleWeightedBackPropStrategy.java
/src/bots/mctsbot/ai/bots/bot/gametree/tls/SimulatedGame.java
/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/tests/Test.java

=======================================
--- /dev/null
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/metatree/TLSTree.java Thu
May 5 02:17:36 2011
@@ -0,0 +1,68 @@
+package bots.mctsbot.ai.bots.bot.gametree.tls.metatree;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import bots.mctsbot.ai.bots.bot.gametree.tls.nodes.AbstractTLSNode;
+import bots.mctsbot.ai.bots.bot.gametree.tls.nodes.LeafNode;
+import bots.mctsbot.ai.bots.bot.gametree.tls.nodes.RootNode;
+import
bots.mctsbot.ai.bots.bot.gametree.tls.strategies.selection.SelectionStrategy;
+import bots.mctsbot.common.elements.player.PlayerId;
+
+public abstract class TLSTree {
+
+ public final PlayerId player;
+
+ public PlayerId getPlayer() {
+ return player;
+ }
+
+ public RootNode getRoot() {
+ return root;
+ }
+
+ public AbstractTLSNode getParent() {
+ return parent;
+ }
+
+ public final RootNode root;
+ public final AbstractTLSNode parent;
+ private final List<LeafNode> children = new ArrayList<LeafNode>();
+
+ public TLSTree(PlayerId player, AbstractTLSNode parent) {
+ this.player = player;
+ this.parent = parent;
+ root = new RootNode(this);
+ }
+
+ public boolean isRoot() {
+ return parent == null;
+ }
+
+ public AbstractTLSNode selectChild(SelectionStrategy
moveSelectionStrategy) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getNbSamples() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public LeafNode selectRecursively() {
+ return root.selectRecursively();
+ }
+
+ /*
+ public LeafNode selectChild() {
+ return selectionStrategy.select(this);
+ }
+ */
+
+ public List<LeafNode> getChildren() {
+ return children;
+ }
+
+ public abstract SelectionStrategy getSelectionStrategy();
+
+}
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/TLSTree.java Thu Apr
28 01:55:39 2011
+++ /dev/null
@@ -1,34 +0,0 @@
-package bots.mctsbot.ai.bots.bot.gametree.tls.nodes;
-
-import bots.mctsbot.common.elements.player.PlayerId;
-
-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;
-
- public TLSTree(PlayerId player, LeafNode parent) {
- this.player = player;
- this.parent = parent;
- root = new RootNode(this);
- }
-
- public boolean isRoot() {
- return parent == null;
- }
-
-}
=======================================
---
/src/bots/mctsbot/ai/bots/bot/gametree/tls/strategies/selection/UCTPlusSelector.java
Wed Apr 27 09:48:06 2011
+++ /dev/null
@@ -1,38 +0,0 @@
-package bots.mctsbot.ai.bots.bot.gametree.tls.strategies.selection;
-
-import bots.mctsbot.ai.bots.bot.gametree.tls.nodes.AbstractTLSNode;
-
-public class UCTPlusSelector extends SelectionStrategy {
-
- private final double C1;
- private final double C2;
-
- public UCTPlusSelector(double C1, double C2) {
- this.C1 = C1;
- this.C2 = C2;
- }
-
- @Override
- public AbstractTLSNode select(AbstractTLSNode innerNode) {
- AbstractTLSNode leftChild = innerNode.getLeftChild();
- double leftValue = evaluate(innerNode.getLeftChild());
-
- AbstractTLSNode rightChild = innerNode.getRightChild();
- if (rightChild == null)
- return leftChild;
-
- if (evaluate(rightChild) >= leftValue)
- return rightChild;
-
- return leftChild;
- }
-
- protected double evaluate(AbstractTLSNode node) {
- int nbSamples = node.getNbSamples();
- if (nbSamples == 0)
- return 0;
- int nbParentSamples = node.getParent().getNbSamples();
- double stdDev = node.getEVStdDev();
- return node.getEV() + C1 * Math.sqrt(Math.log(nbParentSamples) /
nbSamples) + C2 * stdDev;
- }
-}
=======================================
---
/src/bots/mctsbot/ai/bots/bot/gametree/mcts/strategies/backpropagation/SampleWeightedBackPropStrategy.java
Sun Nov 7 06:35:47 2010
+++
/src/bots/mctsbot/ai/bots/bot/gametree/mcts/strategies/backpropagation/SampleWeightedBackPropStrategy.java
Thu May 5 02:17:36 2011
@@ -21,9 +21,14 @@

public class SampleWeightedBackPropStrategy implements
BackPropagationStrategy {

- private final RunningStats stats = new RunningStats();
+ private final RunningStats stats;

public SampleWeightedBackPropStrategy() {
+ stats = new RunningStats();
+ }
+
+ public SampleWeightedBackPropStrategy(RunningStats stats) {
+ this.stats = stats;
}

@Override
@@ -65,6 +70,10 @@
public void onBackPropagate(double value) {
stats.add(value);
}
+
+ public RunningStats getRunningStats() {
+ return stats;
+ }

public static class Factory implements BackPropagationStrategy.Factory {

=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/SimulatedGame.java Wed Apr
27 09:48:06 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/SimulatedGame.java Thu May
5 02:17:36 2011
@@ -18,4 +18,8 @@
*/
private static final long serialVersionUID = -628544300776476142L;

-}
+ public double getValue() {
+ //TODO: implement simulation value
+ return 0;
+ }
+}
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/AbstractTLSNode.java
Mon May 2 07:00:38 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/AbstractTLSNode.java
Thu May 5 02:17:36 2011
@@ -1,13 +1,14 @@
package bots.mctsbot.ai.bots.bot.gametree.tls.nodes;

-import java.util.ArrayList;
-import java.util.List;
-
+import bots.mctsbot.ai.bots.bot.gametree.action.ProbabilityAction;
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.mcts.strategies.backpropagation.SampleWeightedBackPropStrategy;
import bots.mctsbot.ai.bots.bot.gametree.tls.SimulatedGame;
+import bots.mctsbot.ai.bots.bot.gametree.tls.metatree.TLSTree;
import
bots.mctsbot.ai.bots.bot.gametree.tls.strategies.selection.SelectionStrategy;
-import bots.mctsbot.ai.bots.bot.gametree.tls.tests.Test;
+import bots.mctsbot.ai.bots.util.RunningStats;
+import bots.mctsbot.client.common.gamestate.GameState;
+import bots.mctsbot.common.elements.player.PlayerId;

public abstract class AbstractTLSNode {

@@ -16,15 +17,14 @@

private final TLSTree tree;

- protected BackPropagationStrategy backPropagationStrategy;
-
- private int nbSamples = 0;
-
- protected List<Test> possibleTests = new ArrayList<Test>();
-
- public AbstractTLSNode(AbstractTLSNode parent, TLSTree tree) {
+ protected SampleWeightedBackPropStrategy backPropagationStrategy;
+
+ //protected List<Test> possibleTests = new ArrayList<Test>();
+
+ public AbstractTLSNode(AbstractTLSNode parent, TLSTree tree, RunningStats
stats) {
this.parent = parent;
this.tree = tree;
+ this.backPropagationStrategy = new SampleWeightedBackPropStrategy(stats);
}

private final AbstractTLSNode parent;
@@ -45,31 +45,26 @@
return parent;
}

- public void backPropagate(double value, SimulatedGame game) {
+ public void backPropagate(SimulatedGame game) {
SearchBotAction action = game.peek();
- if (!isSplit()) {
- for (Test test : possibleTests) {
- test.updateStats(action, value);
- }
- }
- backPropagationStrategy.onBackPropagate(value);
- this.getParent().backPropagate(value, game);
+ backPropagationStrategy.onBackPropagate(game.getValue());
+ this.getParent().backPropagate(game);
}

- protected boolean isSplit() {
- return rightChild != null;
- }
-
- /**
- * For now when a node is split, all information down the tree is lost.
- */
- public void split() {
- leftChild = new LeafNode(getParent(), getTree());
- rightChild = new LeafNode(getParent(), getTree());
- }
+ // protected boolean isSplit() {
+ // return rightChild != null;
+ // }
+ //
+ // /**
+ // * For now when a node is split, all information down the tree is lost.
+ // */
+ // public void split() {
+ // leftChild = new LeafNode(getParent(), getTree());
+ // rightChild = new LeafNode(getParent(), getTree());
+ // }

public int getNbSamples() {
- return nbSamples;
+ return backPropagationStrategy.getNbSamples();
}

public double getEVStdDev() {
@@ -87,5 +82,32 @@
public TLSTree getTree() {
return tree;
}
+
+ public ProbabilityAction getLastAction() {
+ //TODO:fix implementation
+ return null;
+ }
+
+ public GameState getGameState() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public PlayerId getBot() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public LeafNode selectRecursively() {
+ return getTree().getSelectionStrategy().select(this).selectRecursively();
+ }
+
+ public void replaceNode(LeafNode original, InnerNode replacement) {
+ if (getLeftChild() == original)
+ leftChild = replacement;
+ if (getRightChild() == original)
+ rightChild = replacement;
+ assert false;
+ }

}
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/InnerNode.java Thu Apr
28 01:55:39 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/InnerNode.java Thu
May 5 02:17:36 2011
@@ -1,10 +1,16 @@
package bots.mctsbot.ai.bots.bot.gametree.tls.nodes;

+import bots.mctsbot.ai.bots.bot.gametree.tls.metatree.TLSTree;
+import bots.mctsbot.ai.bots.bot.gametree.tls.tests.Test;
+import bots.mctsbot.ai.bots.util.RunningStats;

public class InnerNode extends AbstractTLSNode {

- public InnerNode(AbstractTLSNode parent, TLSTree tree) {
- super(parent, tree);
+ public Test test;
+
+ public InnerNode(AbstractTLSNode parent, TLSTree tree, Test test,
RunningStats stats) {
+ super(parent, tree, stats);
+ this.test = test;
}

}
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/LeafNode.java Thu Apr
28 01:55:39 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/LeafNode.java Thu May
5 02:17:36 2011
@@ -1,14 +1,87 @@
package bots.mctsbot.ai.bots.bot.gametree.tls.nodes;

-public class LeafNode extends InnerNode {
+import java.util.ArrayList;
+import java.util.List;
+
+import bots.mctsbot.ai.bots.bot.gametree.action.SearchBotAction;
+import bots.mctsbot.ai.bots.bot.gametree.tls.SimulatedGame;
+import bots.mctsbot.ai.bots.bot.gametree.tls.metatree.TLSTree;
+import bots.mctsbot.ai.bots.bot.gametree.tls.tests.Test;
+import bots.mctsbot.ai.bots.util.RunningStats;
+
+public class LeafNode extends AbstractTLSNode {

public TLSTree childTree;
-
- public LeafNode(AbstractTLSNode parent, TLSTree tree) {
- super(parent, tree);
+ private List<Test> possibleTests = null;
+ private List<SearchBotAction> samples = new ArrayList<SearchBotAction>();
+
+ public LeafNode(AbstractTLSNode parent, TLSTree tree, RunningStats stats)
{
+ super(parent, tree, stats);
}

public void expand() {
- childTree = new TLSTree(this.getTree().getPlayer(), this);
+ //TODO:FIX EXPANSION
+ //childTree = new TLSTree(this.getTree().getPlayer(), this);
+ }
+
+ public LeafNode selectRecursively() {
+ if (childTree == null)
+ return this;
+ return childTree.selectRecursively();
+ }
+
+ public SimulatedGame simulate() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void backPropagate(SimulatedGame game) {
+ if (possibleTests == null) {
+ samples.add(game.peek());
+ if (timeToGenerateTests())
+ generateTests();
+ }
+ if (possibleTests != null) {
+ for (Test test : possibleTests) {
+ test.updateStats(game.peek(), game.getValue());
+ }
+ if (needsToBeSplit())
+ split();
+ }
+ super.backPropagate(game);
+ }
+
+ private void generateTests() {
+ // TODO Auto-generated method stub
+ possibleTests = new ArrayList<Test>();
+ }
+
+ private boolean timeToGenerateTests() {
+ return samples.size() > 10;
+ }
+
+ private void split() {
+ Test test = getBestTest();
+ LeafNode leftChild = new LeafNode(this.getParent(), getTree(),
test.getLeftStats());
+ LeafNode rightChild = new LeafNode(this.getParent(), getTree(),
test.getRightStats());
+
+ if (getParent().getRightChild() == null)
+ ((RootNode) getParent()).introduceSplit(test, leftChild, rightChild);
+ else {
+ InnerNode newNode = new InnerNode(getParent(), getTree(), test,
this.backPropagationStrategy.getRunningStats());
+ newNode.leftChild = leftChild;
+ newNode.rightChild = rightChild;
+ getParent().replaceNode(this, newNode);
+ }
+ }
+
+ private Test getBestTest() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ private boolean needsToBeSplit() {
+ return getNbSamples() > 30;
}
}
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/RootNode.java Thu Apr
28 01:55:39 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/RootNode.java Thu May
5 02:17:36 2011
@@ -1,18 +1,21 @@
package bots.mctsbot.ai.bots.bot.gametree.tls.nodes;

import bots.mctsbot.ai.bots.bot.gametree.tls.SimulatedGame;
-
-public class RootNode extends AbstractTLSNode {
+import bots.mctsbot.ai.bots.bot.gametree.tls.metatree.TLSTree;
+import bots.mctsbot.ai.bots.bot.gametree.tls.tests.Test;
+import bots.mctsbot.ai.bots.util.RunningStats;
+
+public class RootNode extends InnerNode {

public RootNode(TLSTree tree) {
- super(null, tree);
- this.leftChild = new LeafNode(this, this.getTree());
+ super(null, tree, null, new RunningStats());
+ this.leftChild = new LeafNode(this, this.getTree(), new RunningStats());
}

@Override
- public void backPropagate(double value, SimulatedGame game) {
+ public void backPropagate(SimulatedGame game) {
if (!this.getTree().isRoot()) {
- super.backPropagate(value, game);
+ super.backPropagate(game);
game.pop();
}
}
@@ -21,5 +24,11 @@
public AbstractTLSNode getParent() {
return this.getTree().getParent();
}
+
+ public void introduceSplit(Test test, LeafNode leftChild, LeafNode
rightChild) {
+ this.test = test;
+ this.leftChild = leftChild;
+ this.rightChild = rightChild;
+ }

}
=======================================
--- /src/bots/mctsbot/ai/bots/bot/gametree/tls/tests/Test.java Mon May 2
07:00:38 2011
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/tests/Test.java Thu May 5
02:17:36 2011
@@ -55,4 +55,12 @@
return node.getStdDev() - failStats.getNbSamples() / node.getNbSamples()
* failStats.getStdDev() - successStats.getNbSamples() / node.getNbSamples()
* successStats.getStdDev();
}
-}
+
+ public RunningStats getLeftStats() {
+ return failStats;
+ }
+
+ public RunningStats getRightStats() {
+ return successStats;
+ }
+}

==============================================================================
Revision: 116cccca8f3e
Author: thijs
Date: Thu May 5 02:18:17 2011
Log: updated metatree structure and bot builded
http://code.google.com/p/opentestbed/source/detail?r=116cccca8f3e

Added:
/src/bots/mctsbot/ai/bots/bot/gametree/tls/TLSBot.java
/src/bots/mctsbot/ai/bots/bot/gametree/tls/metatree/DecisionTree.java
/src/bots/mctsbot/ai/bots/bot/gametree/tls/metatree/RootTree.java
/src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/Config.java

/src/bots/mctsbot/ai/bots/bot/gametree/tls/strategies/selection/WeightedUCTSelector.java

=======================================
--- /dev/null
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/TLSBot.java Thu May 5
02:18:17 2011
@@ -0,0 +1,56 @@
+package bots.mctsbot.ai.bots.bot.gametree.tls;
+
+import java.rmi.RemoteException;
+
+import bots.mctsbot.ai.bots.bot.AbstractBot;
+import bots.mctsbot.ai.bots.bot.gametree.action.IllegalActionException;
+import bots.mctsbot.ai.bots.bot.gametree.action.SearchBotAction;
+import bots.mctsbot.ai.bots.bot.gametree.tls.metatree.RootTree;
+import bots.mctsbot.ai.bots.bot.gametree.tls.nodes.LeafNode;
+import bots.mctsbot.client.common.GameStateContainer;
+import
bots.mctsbot.common.api.lobby.holdemtable.holdemplayer.context.RemoteHoldemPlayerContext;
+import bots.mctsbot.common.elements.player.PlayerId;
+
+public class TLSBot extends AbstractBot {
+
+ private final int decisionTime;
+
+ public TLSBot(PlayerId botId, GameStateContainer gameStateContainer,
RemoteHoldemPlayerContext playerContext, int decisionTime) {
+ super(botId, gameStateContainer, playerContext);
+ this.decisionTime = decisionTime;
+ }
+
+ @Override
+ public void doNextAction() {
+ long startTime = System.currentTimeMillis();
+ RootTree root = new RootTree(botId);
+
+ do {
+ for (int i = 0; i < 34; i++)
+ iterate(root);
+ } while (System.currentTimeMillis() < startTime + decisionTime);
+
+ SearchBotAction action = root.getBestAction();
+
+ try {
+ action.perform(playerContext);
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalActionException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ private void iterate(RootTree root) {
+ LeafNode leaf = root.selectRecursively();
+
+ //does nothing yet
+ leaf.expand();
+
+ SimulatedGame game = leaf.simulate();
+ leaf.backPropagate(game);
+ }
+}
=======================================
--- /dev/null
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/metatree/DecisionTree.java
Thu May 5 02:18:17 2011
@@ -0,0 +1,22 @@
+package bots.mctsbot.ai.bots.bot.gametree.tls.metatree;
+
+import bots.mctsbot.ai.bots.bot.gametree.tls.nodes.AbstractTLSNode;
+import
bots.mctsbot.ai.bots.bot.gametree.tls.strategies.selection.SelectionStrategy;
+import
bots.mctsbot.ai.bots.bot.gametree.tls.strategies.selection.WeightedUCTSelector;
+import bots.mctsbot.common.elements.player.PlayerId;
+
+public class DecisionTree extends TLSTree {
+
+ public DecisionTree(PlayerId player, AbstractTLSNode parent) {
+ super(player, parent);
+ // TODO Auto-generated constructor stub
+ }
+
+ private final SelectionStrategy selectionStrategy = new
WeightedUCTSelector(108.6957);
+
+ @Override
+ public SelectionStrategy getSelectionStrategy() {
+ return selectionStrategy;
+ }
+
+}
=======================================
--- /dev/null
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/metatree/RootTree.java Thu
May 5 02:18:17 2011
@@ -0,0 +1,18 @@
+package bots.mctsbot.ai.bots.bot.gametree.tls.metatree;
+
+import bots.mctsbot.ai.bots.bot.gametree.action.SearchBotAction;
+import bots.mctsbot.common.elements.player.PlayerId;
+
+public class RootTree extends DecisionTree {
+
+ public RootTree(PlayerId player) {
+ super(player, null);
+ // TODO Auto-generated constructor stub
+ }
+
+ public SearchBotAction getBestAction() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
=======================================
--- /dev/null
+++ /src/bots/mctsbot/ai/bots/bot/gametree/tls/nodes/Config.java Thu May 5
02:18:17 2011
@@ -0,0 +1,74 @@
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
+ */
+package bots.mctsbot.ai.bots.bot.gametree.tls.nodes;
+
+import bots.mctsbot.ai.bots.bot.gametree.mcts.nodes.ShowdownNode.Factory;
+import
bots.mctsbot.ai.bots.bot.gametree.mcts.strategies.backpropagation.BackPropagationStrategy;
+import bots.mctsbot.ai.bots.bot.gametree.search.expander.sampling.Sampler;
+import
bots.mctsbot.ai.bots.bot.gametree.tls.strategies.selection.SelectionStrategy;
+import bots.mctsbot.ai.opponentmodels.OpponentModel;
+
+public class Config {
+
+ //private final Factory showdownNodeFactory;
+ private final OpponentModel model;
+ private final SelectionStrategy decisionNodeSelectionStrategy;
+ private final SelectionStrategy opponentNodeSelectionStrategy;
+ private final SelectionStrategy moveSelectionStrategy;
+ private final BackPropagationStrategy.Factory backPropStratFactory;
+ private final Sampler sampler;
+
+ public Config(OpponentModel model, SelectionStrategy
decisionNodeSelectionStrategy, SelectionStrategy
opponentNodeSelectionStrategy,
+ SelectionStrategy moveSelectionStrategy,
BackPropagationStrategy.Factory backPropStratFactory, Sampler sampler) {
+ this.model = model;
+ //this.showdownNodeFactory = showdownNodeFactory;
+ this.decisionNodeSelectionStrategy = decisionNodeSelectionStrategy;
+ this.opponentNodeSelectionStrategy = opponentNodeSelectionStrategy;
+ this.moveSelectionStrategy = moveSelectionStrategy;
+ this.backPropStratFactory = backPropStratFactory;
+ this.sampler = sampler;
+ }
+
+ public OpponentModel getModel() {
+ return model;
+ }
+
+ /*
+ public Factory getShowdownNodeFactory() {
+ return showdownNodeFactory;
+ }*/
+
+ public SelectionStrategy getMoveSelectionStrategy() {
+ return moveSelectionStrategy;
+ }
+
+ public SelectionStrategy getDecisionNodeSelectionStrategy() {
+ return decisionNodeSelectionStrategy;
+ }
+
+ public BackPropagationStrategy.Factory getBackPropStratFactory() {
+ return backPropStratFactory;
+ }
+
+ public SelectionStrategy getOpponentNodeSelectionStrategy() {
+ return opponentNodeSelectionStrategy;
+ }
+
+ public Sampler getSampler() {
+ return sampler;
+ }
+
+}
=======================================
--- /dev/null
+++
/src/bots/mctsbot/ai/bots/bot/gametree/tls/strategies/selection/WeightedUCTSelector.java
Thu May 5 02:18:17 2011
@@ -0,0 +1,67 @@
+package bots.mctsbot.ai.bots.bot.gametree.tls.strategies.selection;
+
+import bots.mctsbot.ai.bots.bot.gametree.tls.nodes.AbstractTLSNode;
+import bots.mctsbot.client.common.gamestate.GameState;
+import bots.mctsbot.client.common.playerstate.PlayerState;
+import bots.mctsbot.common.elements.player.PlayerId;
+
+public class WeightedUCTSelector extends SelectionStrategy {
+
+ private final double C;
+
+ public WeightedUCTSelector(double C) {
+ this.C = C;
+ }
+
+ @Override
+ public AbstractTLSNode select(AbstractTLSNode node) {
+ AbstractTLSNode leftChild = node.getLeftChild();
+ double leftValue = evaluate(leftChild);
+
+ AbstractTLSNode rightChild = node.getRightChild();
+ if (rightChild == null)
+ return leftChild;
+
+ if (evaluate(rightChild) >= leftValue)
+ return rightChild;
+
+ return leftChild;
+ }
+
+ protected double evaluate(AbstractTLSNode node) {
+ int nbSamples = node.getNbSamples();
+ if (nbSamples == 0)
+ return 0;
+ int nbParentSamples = node.getParent().getNbSamples();
+ return node.getEV() + getC2(node) * Math.sqrt(Math.log(nbParentSamples)
/ nbSamples);
+ }
+
+ // C2 = C * (maxProfit - maxLoss) maxLoss is negative
+ private double getC2(AbstractTLSNode node) {
+ GameState gameState = node.getGameState();
+ PlayerId bot = node.getBot();
+
+ //wrong assumption if bot is already all-in and doesn't match opponents
bets
+ int maxProfit = gameState.getGamePotSize();
+
+ int botStack = gameState.getPlayer(bot).getStack();
+
+ int maxOpponentStack = 0;
+
+ for (PlayerState playerState : gameState.getAllSeatedPlayers()) {
+ if (playerState.getPlayerId() != bot && !playerState.hasFolded()) {
+ int stack = playerState.getStack();
+ // from each player you can win nothing more than the minimum of his
stack and yours
+ maxProfit += Math.min(botStack, stack);
+
+ maxOpponentStack = Math.max(maxOpponentStack, stack);
+ }
+ }
+
+ int maxLoss = Math.min(botStack, maxOpponentStack);
+
+ //we add up because we took the maxLoss positive here
+ return C * (maxProfit + maxLoss);
+ }
+
+}

Reply all
Reply to author
Forward
0 new messages