拟由人工智能玩的棋盘游戏的Python实现

abalone-boai的Python项目详细描述


鲍鱼博爱GitHub StarsGitHub Forks

LicensePipenv locked Python versionCodecov

这是棋盘游戏Abalone的Python实现。在

它主要是为了让人工智能玩,但也提供了作为人类玩家的选择。在

Screenshot

命令行用法

运行游戏的最小命令行界面由^{}提供。从^{}目录运行:

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

<black player><white player>分别替换为人工智能(如果你想自己玩的话,也可以是人类玩家)。在

例如,与一个随机移动的AI比赛:

^{pr2}$

加载您自己的AI与<module>.<class>类似。在

鲍鱼规则

来自WikipediaCC 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 positionBlack opens with a broadside moveWhite counters with an in-line move
Abalone StandardAbalone BroadsideAbalone 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.

写你自己的人工智能

为了编写自己的AI,请创建一个python文件,其中包含继承自^{}的类,并实现turn方法:

fromabstract_playerimportAbstractPlayerclassMyPlayer(AbstractPlayer):defturn(self,game,moves_history):pass# TODO: implement

查看^{}中的示例实现。在

有关参数和返回类型的详细信息,请参阅documentation。在

一个特别有用的方法是^{}。它产生了人工智能可以执行的所有合法行动。turn方法可以简单地返回一个生成的值。在

“移动”

turn方法的返回值称为move。这是一个元组,它首先包含要移动的弹珠,其次是运动方向。
弹珠由它们在板上的位置指定(见本文件开头的图像,了解空格的符号)。所有空格都列在^{}枚举中。对于内联移动,只指定要移动的行的尾部大理石(“caboose”)。对于横向移动,只有最外层的两个弹珠组成一个元组。
元组的第二个元素是运动方向。这些都列在^{}枚举中。 因此,上面图片中的两个移动示例(请参见Abalone Rules)如下所示:

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

贡献

欢迎各位投稿。有关详细信息,请参见^{}。在

另请参见

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java ParsePushReceiver参数   java如何从设备读取完整数据?   java将java_设置为home,但忽略错误   java如何从歌曲中对专辑进行排序?   java libnaude+windows 10 x64+Eclipse   java如何将maven目标更改为如图所示的想法中的quickicon?   java swing布局中心面板,可滚动显示多个窗口窗格   使用MOSQUITO代理的mqtt中的java SSL   java如何通过属性值获取XML字符串   java在服务器每次启动时停止GWT编译   java如何让javac搜索类路径的子目录?   可以比较java中的两个不同类吗?   JAVAAndroid活动内部类中的lang.NoClassDefFoundError   java HttpServletRequest获取请求头参数块   C++socket与java客户端的连接   java如何在Apache commons http客户端上使用SSL客户端证书   使用预编译正则表达式模式提高java速度   JavaRhino将两个已编译脚本合并为一个脚本