Simple Mancala game and strategies written in C
make
After building, run the game with build/mancala
You can either:
- Specify 2 strategies to match, or
- Specify 2 player name to match (2P), or
- Specify 1 strategy and play with it (1P), or
- Specify 0 strategies and let the game randomly pick 2 strategies to match
Available options
-h, --help
: Print the help message-q, --quiet
: Suppress the output of every round
./build/mancala chaotic minimal_first
# chaotic vs. minimal_first
[Round 0]
5 4 3 2 1 0
┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐
┌───┐ │ 4│ │ 4│ │ 4│ │ 4│ │ 4│ │ 4│ ┌───┐
│ │ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ │ │
chaotic │ 0│ │ 0│ minimal_first
─────── │ │ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ │ │
└───┘ │ 4│ │ 4│ │ 4│ │ 4│ │ 4│ │ 4│ └───┘
└───┘ └───┘ └───┘ └───┘ └───┘ └───┘
0 1 2 3 4 5
>>> chaotic selects 2
[Round 1]
5 4 3 2 1 0
┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐
┌───┐ │ 5│ │ 5│ │ 5│ │ 0│ │ 4│ │ 4│ ┌───┐
│ │ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ │ │
chaotic │ 1│ │ 0│ minimal_first
─────── │ │ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ │ │
└───┘ │ 4│ │ 4│ │ 4│ │ 4│ │ 4│ │ 4│ └───┘
└───┘ └───┘ └───┘ └───┘ └───┘ └───┘
0 1 2 3 4 5
>>> chaotic selects 1
...
5 4 3 2 1 0
┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐
┌───┐ │ 0│ │ 0│ │ 0│ │ 0│ │ 0│ │ 0│ ┌───┐
│ │ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ │ │
chaotic │ 18│ │ 30│ minimal_first
│ │ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ │ │ ═════════════
└───┘ │ 0│ │ 0│ │ 0│ │ 0│ │ 0│ │ 0│ └───┘
└───┘ └───┘ └───┘ └───┘ └───┘ └───┘
0 1 2 3 4 5
>>> The winner is minimal_first
- Left/rightmost box: the players' store
- Numbers above/under the pocket: the pocket index
- Underline: the active player of the round
- Double underline: the winner
-
Define your strategy in
src/strategies.inc
E.g.,
STRATEGY(my_strategy)
-
Implement and assign your strategy in a C source file
E.g., in
src/my_strategy.c
:#include "strategy.h" static int strategy(const mancala_t *game, player_t player) { /* Implement your strategy here */ } strategy_t my_strategy = &strategy;
Use Makefile target, match
to run two strategies against each other for multiple times and see the
result. The script will alternates the first player.
make match
P1
: player 1; defaults tochaotic
P2
: player 2; defaults tominimal_first
ROUNDS
: Number of rounds to run; defaults to 100
E.g., matching minimal_first
and maximal_first
for 1000 times
make match P1=minimal_first P2=maximal_first ROUNDS=1000