- 授权协议: MIT
- 开发语言: Python
- 操作系统: 跨平台
- 软件首页: https://github.com/Zulko/easyAI
- 软件文档: http://zulko.github.io/easyAI/
软件介绍
EasyAI是一个纯 Python 编写的人工智能框架,用于双人对弈类游戏,如 Tic Tac Toe、Connect 4、Reversi 等。它可以轻松地定义游戏机制,并与电脑进行对战。
简单示例
首先定义一个游戏规则,并开始与 AI 的比赛:
from easyAI import TwoPlayersGame, Human_Player, AI_Player, Negamax class GameOfBones( TwoPlayersGame ): """ In turn, the players remove one, two or three bones from a pile of bones. The player who removes the last bone loses. """ def __init__(self, players): self.players = players self.pile = 20 # start with 20 bones in the pile self.nplayer = 1 # player 1 starts def possible_moves(self): return ['1','2','3'] def make_move(self,move): self.pile -= int(move) # remove bones. def win(self): return self.pile<=0 # opponent took the last bone ? def is_over(self): return self.win() # Game stops when someone wins. def show(self): print "%d bones left in the pile"%self.pile def scoring(self): return 100 if game.win() else 0 # For the AI # Start a match (and store the history of moves when it ends) ai = Negamax(13) # The AI will think 13 moves in advance game = GameOfBones( [ Human_Player(), AI_Player(ai) ] ) history = game.play()
结果:
20 bones left in the pile Player 1 what do you play ? 3 Move #1: player 1 plays 3 : 17 bones left in the pile Move #2: player 2 plays 1 : 16 bones left in the pile Player 1 what do you play ?