棋盘游戏库

pykhet的Python项目详细描述


https://travis-ci.org/TheWiseLion/pykhet.svg?branch=master

简介

用python实现的khet棋盘游戏逻辑和结构。同时也展示了基于对抗性搜索的算法。

frompykhet.components.typesimportTeamColorfrompykhet.games.game_typesimportClassicGameimportrandomfrompykhet.solvers.minmaximportMinmaxSolver# Create a game with classic piece placementgame=ClassicGame()# Get all valid silver movessilver_moves=game.get_available_moves(TeamColor.silver)# Randomly Play Onegame.apply_move(random.choice(silver_moves))# Finish the turn by applying the lasergame.apply_laser(TeamColor.silver)# Use adversarial search to pick a movesolver=MinmaxSolver()move=solver.get_move(game,TeamColor.red)game.apply_move(move)game.apply_laser(TeamColor.red)

序列化

有足够的支持将对象的状态序列化为字典。有助于作为json轻松存储。

frompykhet.components.typesimportTeamColor,Piecefrompykhet.games.game_typesimportClassicGameimportrandomfrompykhet.solvers.minmaximportMinmaxSolver# Create a game with classic piece placementgame=ClassicGame()# Serialize the board (list of serialized piece positions, orientations, and colors)squares=game.to_serialized_squares()# Deserialize the boardGame.from_serialized_squares(squares)# Serialize a piecesp1=Piece(PieceType.scarab,TeamColor.silver,Orientation.down).to_dictionary()# Deserialize a piecesame_piece=Piece.from_dictionary(p1)

电路板布局

KHET板和工件布局如下所示:

https://raw.githubusercontent.com/TheWiseLion/pykhet/master/docs/board-khet.png

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

推荐PyPI第三方库


热门话题
使用Scala对Java进行单元测试?   java无法将应用程序部署到Tomcat   java如何在IntelliJ IDEA中创建补丁?   java如何在安卓中编程设置列表视图高度   java如何使用charAt检查字符串是否以AZ或AZ开头?   java在SQL查询中使用非限制值   java函数在不同的Android版本中返回不同的datetime值   java方法应该在实现动作的类中,还是在实现的类中?   java从另一个线程的类访问线程类的公共静态arrayList   java是否像重新引发相同的异常?   java如何从localhost访问本地文件   javaurl。openStream非常慢   java数组越界和空指针异常   java我只是在某种程度上破坏了Netbeans,我不知道如何修复它   java是否可以延迟类的加载,而这些类可能在以后动态加载?   java断开外壳输出到文件   从blob服务回调时出现java Google应用程序引擎错误   java将SparseArray存储在JSON中并使用它   使用IText for Java进行pdf文本定位   java如何更改SearchView的样式?