拟由人工智能玩的棋盘游戏的Python实现
abalone-boai的Python项目详细描述
鲍鱼博爱
这是棋盘游戏Abalone的Python实现。在
它主要是为了让人工智能玩,但也提供了作为人类玩家的选择。在
命令行用法
$ ./run_game.py <black player> <white player>
将<black player>
和<white player>
分别替换为人工智能(如果你想自己玩的话,也可以是人类玩家)。在
例如,与一个随机移动的AI比赛:
^{pr2}$加载您自己的AI与<module>.<class>
类似。在
鲍鱼规则
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.
写你自己的人工智能
为了编写自己的AI,请创建一个python文件,其中包含继承自^{turn
方法:
fromabstract_playerimportAbstractPlayerclassMyPlayer(AbstractPlayer):defturn(self,game,moves_history):pass# TODO: implement
查看^{
有关参数和返回类型的详细信息,请参阅documentation。在
一个特别有用的方法是^{turn
方法可以简单地返回一个生成的值。在
“移动”
turn
方法的返回值称为move。这是一个元组,它首先包含要移动的弹珠,其次是运动方向。
弹珠由它们在板上的位置指定(见本文件开头的图像,了解空格的符号)。所有空格都列在^{
元组的第二个元素是运动方向。这些都列在^{
fromenumsimportDirection,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)returnSpace.I8,Direction.SOUTH_WEST
贡献
欢迎各位投稿。有关详细信息,请参见^{
另请参见
- 项目
标签: