ahorn.Actors package¶
Submodules¶
ahorn.Actors.MCTSPlayer module¶
The Monte Carlo Tree Search player is a generic player, and can be used in games of incomplete information and with chance events.
It is based on the Monte Carlo Tree Search algorithm.
-
class
ahorn.Actors.MCTSPlayer.
MCTSPlayer
(exploration_exploitation=1.4, simulation_count=10000, simulation_time=90, verbose=False, verboseverbose=False)¶ Bases:
ahorn.GameBase.Actor.Actor
A player who uses the Monte Carlo Tree Search algorithm.
- exploration_exploitation: float
- the exploration/exploitation parameter
- simulation_count: int
- maximum number of simulations
- simulation_time: float
- maximum seconds of simulation time
- verbose: bool
- print some information
- verboseverbose: bool
- print even more information
-
backpropagation_phase
(expanded_node, utility)¶ The backpropagation phase of the MCTS algorithm.
This phase will update the constructed MCTS tree based on the utility vector from the simulation
- expanded_node: TreeNode
- The node from where to start backpropagation
- utility: List<float>
- The utility vector from the simulation phase
-
expansion_phase
(selected_node, selected_state, action)¶ The expansion phase of the MCTS algorithm.
This expansion will add a node to the constructed MCTS tree,
- selected_node: TreeNode
- The node which needs to be expanded
- selected_state: State
- The State corresponding to the selected_node
- action: Action
- The action by which the selected node needs to be expanded
- expanded_node: TreeNode
- The new node added to the constructed MCTS tree
- expanded_state: State
- The State corresponding to expanded_node
-
get_action
(state)¶ Return the best action according to MCTS algorithm
- state: State
- The state in which the actor must perform an action
- action: Action
- Best action according to MCTS algorithm
-
selection_phase
(root_node, root_state)¶ The selection phase of the MCTS algorithm.
This phase will analyse the constructed MCTS tree, use UCT to traverse down the tree, until a root node is reached.
- root_node: TreeNode
- The root tree node from where to start selection phase
- root_state: State
- The State corresponding to the root_node
- selected_node: TreeNode
- The node in the MCTS tree that needs to be expanded
- selected_state: State
- The State corresponding to selected_node
- action: Action
- The action by which the selected node should be expanded with
-
simulation_phase
(expanded_state)¶ The simulation phase of the MCTS algorithm.
This phase will simulate a random playout from a given state
- expanded_state: State
- The state from where to start the random playout
- utility: List
- The utility vector of the final state
-
class
ahorn.Actors.MCTSPlayer.
TreeNode
(utility=None, simulations=0, parent=None, children=None)¶ Bases:
object
A tree node to build internal game tree for MCTS algorithm
- utility: List
- A utility vector with the utility for each player, for example [-1, 1] in a game with 2 players.
- simulations: int
- An number signifying how many times this node has been visited during the MCTS algorithm
- parent: TreeNode
- The parent of this node
- children: dict<Action -> TreeNode>
- A dictionary with actions as the keys, and treenodes as the values
-
is_leaf
()¶ True if this node is a leaf of the tree.
- is_leaf: Bool
- True if node is a leaf, False if node is not a leaf
ahorn.Actors.RandomActor module¶
-
class
ahorn.Actors.RandomActor.
RandomActor
¶ Bases:
ahorn.GameBase.Actor.Actor
An actor who always choses random actions.
-
get_action
(state)¶ Return a random action from the legal actions
- State:
- The state in which the actor must perform an action
- Action:
- A random action from the legal actions
-
ahorn.Actors.RandomPlayer module¶
-
class
ahorn.Actors.RandomPlayer.
RandomPlayer
¶ Bases:
ahorn.Actors.RandomActor.RandomActor
,ahorn.GameBase.Player.Player
A player who takes a random action from the list of legal actions.