python 人工智能库_EasyAI是一个纯 Python 编写的人工智能框架

easyAI

EasyAI (full documentation here) is a pure-Python artificial intelligence framework for two-players abstract games such as Tic Tac Toe, Connect 4, Reversi, etc. It makes it easy to define the mechanisms of a game, and play against the computer or solve the game. Under the hood, the AI is a Negamax algorithm with alpha-beta pruning and transposition tables as described on Wikipedia.

Installation

If you have pip installed, type this in a terminal

sudo pip install easyAI

Otherwise, dowload the source code (for instance on Github), unzip everything into one folder and in this folder, in a terminal, type

sudo python setup.py install

Additionnally you will need to install Numpy to be able to run some of the examples.

A quick example

Let us define the rules of a game and start a match against the 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()

Result:

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 ?

Solving the game

Let us now solve the game:

from easyAI import id_solve

r,d,m = id_solve(GameOfBones, ai_depths=range(2,20), win_score=100)

We obtain r=1, meaning that if both players play perfectly, the first player to play can always win (-1 would have meant always lose), d=10, which means that the wins will be in ten moves (i.e. 5 moves per player) or less, and m='3', which indicates that the first player's first move should be '3'.

These computations can be sped up using a transposition table which will store the situations encountered and the best moves for each:

tt = TT()

GameOfBones.ttentry = lambda game : game.pile # key for the table

r,d,m = id_solve(GameOfBones, range(2,20), win_score=100, tt=tt)

After these lines are run the variable tt contains a transposition table storing the possible situations (here, the possible sizes of the pile) and the optimal moves to perform. With tt you can play perfectly without thinking:

.. code:: python

game = GameOfBones( [ AI_Player( tt ), Human_Player() ] ) game.play() # you will always lose this game :)

Contribute !

EasyAI is an open source software originally written by Zulko and released under the MIT licence. It could do with some improvements, so if your are a Python/AI guru maybe you can contribute through Github . Some ideas: AI algos for incomplete information games, better game solving strategies, (efficient) use of databases to store moves, AI algorithms using parallelisation.

For troubleshooting and bug reports, the best for now is to ask on Github.

Maintainers

easyAi一个用java进行开发的傻瓜ai框架,无需任何算法知识,通过简单的api调用就可以实现常用的图像内物体的识别,定位等图像ai服务,及自然语言分类处理服务。面向java开发程序员,不依赖任何第三方,第三方接口,独立包。直接引入maven项目pom文件,就可以执行人工智能任务。easyAi说明本包原名imageMarket,因为开始加入自然语言模块,所以之后更名为easyAi。 本包对物体在图像中进行训练及识别,切割,定位的轻量级,面向小白的框架,功能在逐渐扩展中。 本包对中文输入语句,对输入语句的类别进行分类,功能在逐渐扩展中。easyAi软件目的 低硬件成本,CPU可快速学习运行,面向Java开发的程序员,经过简单API调用就可实现物体在图像中的识别、定位及中文语言分类等功能; 努力为中小企业提供AI场景解决技术方案,AI内核驱动力!为什么做easyAi这个包1、低门槛化:现在随着人工智能技术的兴起,很多场景需要开发人员添加相应的功能,但是在二三线城市算法人才匮乏,并且大多是Java开发程序员,业务做的更多,因为作者本人就是三线城市程序员,所以深知这一点。所以需要一款部署简单,不需要学习任何算法知识,只通过最简单的API调用,就可以实现部分人工智能应用,并面向覆盖面最广的Java程序员使用的,且能满足大部分AI业务场景实现的技术包。 2、面向用户:广大没接触过算法知识,人才相对匮乏的二三线Java业务开发程序员,实现人工智能应用。 3、部署简单:本包所有底层函数及数学都是作者Java手写,不依赖任何第三方,所以开发者只需要将本包下载到本地后,打成JAR包,引入到自己的POM文件中,就可以独立使用所有功能。 4、功能还在扩展:本包现在的功能还在逐步扩展中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值