You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> This section is highly technical; feel free to skip it and play with the code right away.
50
50
51
-
#### Agents
51
+
#### Algorithms for Board Games
52
52
53
53
Most computer algorithms discretize the game into states and actions. Here, the state is the position of the pawns and the available actions are the possible moves of the pawns.
54
54
55
55
Squadro is a finite state machine, meaning that the next state of the game is completely determined by the current state and the action played. With this definition, one can see that the game is a Markov Decision Process (MDP). At each state, the current player can play different actions, which lead to different states. Then the next player can play different actions from any of those new states, etc. The future of the game can be represented as a tree, whose branches are the actions that lead to different states.
56
56
57
+
#### Exploration - Exploitation trade-off
58
+
57
59
An algorithm can explore that space of possibilities to infer the best move to play now. As the tree is huge, it is not possible to explore all the possible paths until the end of the game. Typically, they explore only a small fraction of the tree and then use the information gathered from those states to make a decision. More precisely, those two phases are:
58
60
59
61
***State exploration**: exploring the space of states by a careful choice of actions. The most common exploration methods are Minimax and Monte Carlo Tree Search (MCTS). Minimax explores all the states up to a specific depth, while MCTS navigates until it finds a state that has not been visited yet. Minimax can be sped up by skipping the search in the parts of the tree that won't affect the final decision; this method is called alpha-beta pruning.
@@ -63,13 +65,15 @@ An algorithm can explore that space of possibilities to infer the best move to p
63
65
* Q value function, a lookup table for each state and action;
64
66
* deep Q network (DQN), a neural network that approximates the Q value function, which is necessary when the state space is huge (i.e., cannot be stored in memory).
65
67
66
-
List of available agents:
68
+
#### Agents
69
+
70
+
At least 8 agents, each running a different algorithm, have been implemented to play the game:
67
71
68
72
*_human_: another local human player (i.e., both playing on the same computer)
69
73
*_random_: a computer that plays randomly among all available moves
70
74
*_ab_relative_advancement_: a computer that lists the possible moves from the current position and evaluates them directly (i.e., it "thinks" only one move ahead), where the evaluation function is the player's advancement
71
75
*_relative_advancement_: a computer that lists the possible moves from the current position and evaluates them directly (i.e., it "thinks" only one move ahead), where the evaluation function is the player's advancement compared to the other player
72
-
*_ab_relative_advancement_: a computer that plays minimax with alpha-beta pruning (depth ~4), where the evaluation function is the player's advancement compared to the other player
76
+
*_ab_relative_advancement_: a computer that plays minimax with alpha-beta pruning, where the evaluation function is the player's advancement compared to the other player
73
77
*_mcts_advancement_: Monte Carlo tree search, where the evaluation function is the player's advancement compared to the other player
74
78
*_mcts_rollout_: Monte Carlo tree search, where the evaluation function is determined by a random playout until the end of the game
75
79
*_mcts_q_learning_: Monte Carlo tree search, where the evaluation function is determined by a lookup table
@@ -83,6 +87,18 @@ import squadro
83
87
print(squadro.AVAILABLE_AGENTS)
84
88
```
85
89
90
+
#### Benchmark
91
+
92
+
All the agents have been evaluated against each other under controlled conditions:
93
+
- Max 3 sec per move
94
+
- 100 games (exactly balanced across the four starting configurations—which color and who starts) except when a human is involved (only 5 games then)
95
+
- Original grid (5 x 5)
96
+
97
+
Here is the comparison:
98
+
99
+
TODO
100
+
101
+
The deep Q-learning algorithm outperforms all other players, including the human (myself, an average player).
86
102
87
103
## Usage
88
104
@@ -150,22 +166,23 @@ Here are the online pre-trained models:
Those models are all very lightweight, making them convenient even for machines with limited resources and fast games.
160
176
161
177
To use those models, simply instantiate the corresponding agent **without** passing the `model_path` argument (this is how the package makes the distinction between loading an online model and creating a new model).
162
178
163
179
```python
164
-
from squadro importMonteCarloDeepQLearningAgent, MonteCarloQLearningAgent
180
+
importsquadro
165
181
166
-
agent_ql=MonteCarloQLearningAgent() # Deep Q-Learning
0 commit comments