Package: easyAI
EasyAI (full documentationhere) 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 onWikipedia.InstallationIf you havepipinstalled, type this in a terminalsudo pip install easyAIOtherwise, download the source code (for instance onGithub), unzip everything into one folder and in this folder, in a terminal, typesudo python setup.py installAdditionally you will need to install Numpy to be able to run some of the examples.A quick exampleLet us define the rules of a game and start a match against the AI:fromeasyAIimportTwoPlayerGame,Human_Player,AI_Player,NegamaxclassGameOfBones(TwoPlayerGame):""" 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=None):self.players=playersself.pile=20# start with 20 bones in the pileself.current_player=1# player 1 startsdefpossible_moves(self):return['1','2','3']defmake_move(self,move):self.pile-=int(move)# remove bones.defwin(self):returnself.pile<=0# opponent took the last bone ?defis_over(self):returnself.win()# Game stops when someone wins.defshow(self):print("%dbones left in the pile"%self.pile)defscoring(self):return100ifgame.win()else0# 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 advancegame=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 gameLet us now solve the game:fromeasyAIimportsolve_with_iterative_deepeningr,d,m=solve_with_iterative_deepening(game=GameOfBones(),ai_depths=range(2,20),win_score=100)We obtainr=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, andm='3', which indicates that the first player’s first move should be'3'.These computations can be speed up using a transposition table which will store the situations encountered and the best moves for each:tt=TranspositionTable()GameOfBones.ttentry=lambdagame:game.pile# key for the tabler,d,m=solve_with_iterative_deepening(game=GameOfBones(),ai_depths=range(2,20),win_score=100,tt=tt)After these lines are run the variablettcontains a transposition table storing the possible situations (here, the possible sizes of the pile) and the optimal moves to perform. Withttyou can play perfectly withoutthinking:game=GameOfBones([AI_Player(tt),Human_Player()])game.play()# you will always lose this game :)Contribute !EasyAI is an open source software originally written byZulkoand released under the MIT licence. Contributions welcome! 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 onGithub.MaintainersZulko(owner)JohnAD