Skip to main content

Abalone BoAI GitHub Stars GitHub Forks

License Pipenv locked Python version Codecov

This is a Python implementation of the board game Abalone.

It is primarily intended to be played by artificial intelligence, but also offers the option to play as a human player.

Screenshot

Command Line Usage

A minimal command line interface for running a game is provided by abalone/run_game.py. From the abalone directory run:

$ ./run_game.py <black player> <white player>

Replace <black player> and <white player> each with an artificial intelligence (or human player if you want to play yourself).

For instance, play against an AI that makes random moves:

$ ./run_game.py human_player.HumanPlayer random_player.RandomPlayer

Loading your own AI works analogously with <module>.<class>.

Abalone Rules

From Wikipedia (CC BY-SA):

Abalone is an award-winning two-player abstract strategy board game designed by Michel Lalet and Laurent Lévi in 1987. Players are represented by opposing black and white marbles on a hexagonal board with the objective of pushing six of the opponent's marbles off the edge of the board.
The board consists of 61 circular spaces arranged in a hexagon, five on a side. Each player has 14 marbles that rest in the spaces and are initially arranged as shown below, on the left image. The players take turns with the black marbles moving first. For each move, a player moves a straight line of one, two or three marbles of one color one space in one of six directions. The move can be either broadside / arrow-like (parallel to the line of marbles) or in-line / in a line (serial in respect to the line of marbles), as illustrated below.

Initial position Black opens with a broadside move White counters with an in-line move
Abalone Standard Abalone Broadside Abalone Inline

A player can push their opponent's marbles (a "sumito") that are in a line to their own with an in-line move only. They can only push if the pushing line has more marbles than the pushed line (three can push one or two; two can push one). Marbles must be pushed to an empty space (i.e. not blocked by a marble) or off the board. The winner is the first player to push six of the opponent's marbles off of the edge of the board.

Write Your Own Artificial Intelligence

In order to write your own AI, create a python file with a class that inherits from abstract_player.AbstractPlayer and implement the turn method:

from abstract_player import AbstractPlayer

class MyPlayer(AbstractPlayer):
    def turn(self, game, moves_history):
        pass  # TODO: implement

Have a look at random_player.py for a sample implementation.

Refer to the documentation for details about the parameters and the return type.

A particularly useful method is game.generate_legal_moves(). It yields all legal moves that the AI can perform. The turn method can simply return one of the yielded values.

A "move"

The return value of the turn method is called a move. This is a tuple, which consists firstly of the marbles to be moved and secondly of the direction of movement.
The marbles are specified by the space where they are located on the board (see the image at the beginning of this document for the notation of the spaces). All spaces are listed in the Space enum. For an inline move only the trailing marble ("caboose") of the line to be moved is specified. For a broadside move only the two outermost marbles are given in a tuple.
The second element of the tuple is the direction of movement. These are all listed in the Direction enum. Therefore the two example moves from the images above (see Abalone Rules) would look like this:

from enums import Direction, Space

# Black opens with a broadside move
# (returned from the turn method of the black player)
return (Space.C3, Space.C5), Direction.NORTH_WEST

# White counters with an in-line move
# (returned from the turn method of the white player)
return Space.I8, Direction.SOUTH_WEST

Contribute

All contributions are welcome. See CONTRIBUTING.md for details.

See Also

Release files for abalone-boai 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for abalone-boai 1.0.0
File Size Uploaded
abalone-boai-1.0.0.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for abalone-boai 1.0.0
File Interpreter ABI Platform
abalone_boai-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.7 kB

Release files / abalone-boai-1.0.0.tar.gz

Download URL abalone-boai-1.0.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
950d1166ae53971e60ecaccb4ab955ceca3c0a738afff489d80a00c50a389c3d
BLAKE2b-256 checksum
How to use checksums
13de15181e78ecaabf0bf1017d0127eade5863bbe0a73a40bed91e46796511b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2

Release files / abalone_boai-1.0.0-py3-none-any.whl

Download URL abalone_boai-1.0.0-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0501431fb63297725fe5aa13b48cf6e3ffba7ab660221a081bca278956ee65f
BLAKE2b-256 checksum
How to use checksums
05e09139b674be51bb3d6f0cabfc4eaf0e02c27c38742335bb1ae00e0e91a1e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page