This is the PyMancala tool, under the terms of the GNU General Public License version 3.
PyMancala implements the Mancala - also called Awale, game.
Download the repository and unpack it, or clone with git
. PyMancala package includes the following folders:
Open a terminal application and change directory to PyMancala folder. Then,
PyMancala can optionally be installed with:
>python -m pip install .
>python -m pip install ".[doc, dev, test]"
Start to play with:
>python main.py
Continue to play an existing saved game:
>python main.py saved_games/my_saved_game.json
The game can be configured by fixing the following options:
When playing, the user can interact with the game by either:
Enter a character to perform an action among:
By default, the logging messages are enabled. It allows to see information about the distribution. Disable these messages by changing the 0 value to 30 in the main.py
file, at line:
>>>import logging
>>>logging.getLogger().setLevel(0)
The PyMancala API implements several variants of its rules:
Change these boolean values into the main.py
file to play with the desired rule variants:
>>>import mancala
>>>game = mancala.MancalaGame()
>>>game.set_distribution_ignore_initial_hole(True)
>>>game.set_distribution_ignore_player_store(False)
>>>game.set_distribution_ignore_opponent_store(True)
>>>game.set_distribution_collect_player_seed_arrived_empty(False)
>>>game.set_distribution_keep_turn_when_arrived_empty(False)
>>>game.set_distribution_must_feed_if_opponent_empty(True)
Edit the mancala.mancalagame.strategies.py
file and add your custom function in the class Strategies
.
This function must return an integer value corresponding to the hole to play. Below is an example of a function:
import random
def awesome(self) -> int:
"""Return intelligently a non-empty hole or -1 if the player can't play.
The awesome strategy consists in... doing things to be described here.
:return: (int) Index of a hole
"""
# Get the list of hole indexes that can be played.
candidates = self.__board.candidate_holes()
# Choose one of them
if len(candidates) > 0:
# Choosing a hole among the candidates: That's the point!
# Do the job here...
# ...
my_selected_candidates = candidates
# ...
# Return a random hole among my selected ones
return random.choice(my_selected_candidates)
# Should never happen.
return -1
The strategies can be evaluated thanks to the compare_strategies.py
script.
As soon as you added your custom strategy in the class Strategies
, it will be compared to the "randomly" one.
Your "awesome" strategy should be better!
The script compares all available strategies to the random one on 100 samples.
It creates 50 different games in order to perform 100 comparisons.
Actually each game is played twice: each strategy is alternatively assigned to the Player 1, the player who starts to play.
>python compare_strategies.py
The script is displaying the results like for example:
Evaluate awesome strategy
random strategy won 40 games.
It is supposed that any strategy should be better than the random one - i.e., should win more often;
a very good strategy should significantly win more games.
Here are the currently evaluated strategies:
Evaluate strategy always_first
random strategy won 76 games.
ex aequo on 3 games.
Evaluate strategy always_last
random strategy won 37 games.
ex aequo on 6 games.
Evaluate strategy always_max
random strategy won 23 games.
ex aequo on 8 games.
Evaluate strategy always_min
random strategy won 77 games.
ex aequo on 3 games.
Evaluate strategy can_play_again_or_random
random strategy won 12 games.
ex aequo on 2 games.
Evaluate strategy earn_max_in_store
random strategy won 6 games.
The documentation of the API - Application Programming Interface, is available in HTML and Markdown formats.
Open either the file docs/index.html
in a web browser, or the ".md" files.
Copyright (C) 2023-2024 Brigitte Bigi, contact@sppas.org.
Author web page is https://sppas.org/bigi/.
2023-10-13: Release 0.1a
2023-10-15: Release 0.2a
2023-10-18, Release 0.3a
2024-01-09, Release 0.4
mancalagame
and mancalaui
.