棋盘游戏库

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第三方库


热门话题
Java中的并发监视器和同步关键字   java试图删除学生,但不断出错   java JSONObject到文档   java在不使用Access Bean的情况下获取类中的属性值   安卓和windows phone之间的java共享数据库   java程序不断终止,我不知道为什么   java测量时间并不能证实LinkedList的优势   java InputStream从串行端口读取数据   Jersey 2.29中带有自定义注释的java注入方法参数   JAVA中的异常理解throw关键字   java ORMLite OneToOne关系   使用Play框架和Java解析Json数组   java对象编程中的文件错误   netbeans 8如何安装Java Darcula外观?   java“sort”属性做什么?   是否有支持移位插入的列表实现(Java)?   java Springboot安全性:登录期间密码不匹配   使用NetClient和JsonParser的java连接到服务器只解析第一条消息   java在使用XMLStreamWriter写入数据时将$或欧元等字符写入unicode格式