用于玩跳棋/跳棋标准游戏的库
imparaai-checkers的Python项目详细描述
一个python3库,可以用来玩跳棋/跳棋游戏。这只是一组可以在代码中使用的类,而不是一个交互式的shell checkersgame。
- 版本:1.4.1
假设
这些规则适用于竞争激烈的美国跳棋或英国跳棋。这意味着一个8x8板与力量捕捉和定期国王。
董事会上每个职位的编号为1到32。每个移动都表示为一个数组,有两个值:起始位置和结束位置。所以,如果你要开始一个新游戏,其中一个可用的移动是玩家1的[9, 13]
。如果有一个捕获移动,则结束位置是捕获块将落在的位置(即,从其原始行开始的两行),这可能看起来像[13, 22]
。
每一个片段的移动都是完全不同的,即使移动是多个捕捉序列的一部分。在Portable Draughts Notation中,mutli捕捉序列通常用5-32
来表示(对于一个特别长的跳跃序列),但是在某些情况下,可能有多个路径来实现最终位置。这个游戏需要一个明确的拼写出每个不同的移动在多捕捉系列。
用法
创建新游戏:
fromcheckersimportGamegame=Game()
看看轮到谁了:
game.whose_turn()#1 or 2
获取可能的移动:
game.get_possible_moves()#[[9, 13], [9, 14], [10, 14], [10, 15], [11, 15], [11, 16], [12, 16]]
移动:
game.move([9,13])
检查游戏是否结束:
game.is_over()#True or False
找出谁赢了:
game.get_winner()#None or 1 or 2
查看移动历史记录:
game.moves#[[int, int], [int, int], ...]
根据rules更改连续非捕捉移动限制(默认值40
):
game.consecutive_noncapture_move_limit=20game.move_limit_reached()#True or False
复习黑板上的文章:
forpieceingame.board.pieces:piece.player#1 or 2piece.other_player#1 or 2piece.king#True or Falsepiece.captured#True or Falsepiece.position#1-32piece.get_possible_capture_moves()#[[int, int], [int, int], ...]piece.get_possible_positional_moves()#[[int, int], [int, int], ...]
测试
从根目录运行python3 -m unittest discover
。