A Python implementation of the board game intended to be played by artificial intelligence
Project description
Abalone BoAI
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.
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
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 |
---|---|---|
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file abalone-boai-1.0.0.tar.gz
.
File metadata
- Download URL: abalone-boai-1.0.0.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 950d1166ae53971e60ecaccb4ab955ceca3c0a738afff489d80a00c50a389c3d |
|
MD5 | b6bac65c41dba444747fb71300ccf60b |
|
BLAKE2b-256 | 13de15181e78ecaabf0bf1017d0127eade5863bbe0a73a40bed91e46796511b9 |
File details
Details for the file abalone_boai-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: abalone_boai-1.0.0-py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0501431fb63297725fe5aa13b48cf6e3ffba7ab660221a081bca278956ee65f |
|
MD5 | bb5c84c9b9661390ea593673a5300735 |
|
BLAKE2b-256 | 05e09139b674be51bb3d6f0cabfc4eaf0e02c27c38742335bb1ae00e0e91a1e7 |