easyAI 用于对弈类游戏的人工智能框架开源项目

我要开发同款
匿名用户2017年03月23日
200阅读

技术信息

开源地址
https://github.com/Zulko/easyAI
授权协议
MIT

作品详情

EasyAI是一个纯 Pytho编写的人工智能框架,用于双人对弈类游戏,如TicTacToe、Coect4、Reversi等。它可以轻松地定义游戏机制,并与电脑进行对战。

简单示例

首先定义一个游戏规则,并开始与AI的比赛:

from easyAI import TwoPlayersGame, Huma_Player, AI_Player, Negamaxclass GameOfBoes( TwoPlayersGame ):    """ I tur, the players remove oe, two or three boes from a    pile of boes. The player who removes the last boe loses. """    def __iit__(self, players):        self.players = players        self.pile = 20 # start with 20 boes i the pile        self.player = 1 # player 1 starts    def possible_moves(self): retur ['1','2','3']    def make_move(self,move): self.pile -= it(move) # remove boes.    def wi(self): retur self.pile<=0 # oppoet took the last boe ?    def is_over(self): retur self.wi() # Game stops whe someoe wis.    def show(self): prit "%d boes left i the pile"%self.pile    def scorig(self): retur 100 if game.wi() else 0 # For the AI# Start a match (ad store the history of moves whe it eds)ai = Negamax(13) # The AI will thik 13 moves i advacegame = GameOfBoes( [ Huma_Player(), AI_Player(ai) ] )history = game.play()

结果:

20 boes left i the pilePlayer 1 what do you play ? 3Move #1: player 1 plays 3 :17 boes left i the pileMove #2: player 2 plays 1 :16 boes left i the pilePlayer 1 what do you play ?

功能介绍

EasyAI是一个纯 Python 编写的人工智能框架,用于双人对弈类游戏,如 Tic Tac Toe、Connect 4、Reversi 等。它可以轻松地定义游戏机制,并与电脑进行对战。 简单...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论