easyAI


NameeasyAI JSON
Version 2.0.12 PyPI version JSON
download
home_page
SummaryEasy-to-use game AI algorithms (Negamax etc. )
upload_time2021-08-12 12:42:12
maintainer
docs_urlNone
author
requires_python
licenseLICENSE.txt
keywords board games ai artificial intelligence negamax
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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, download 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

Additionally 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:

.. code:: python

    from easyAI import TwoPlayerGame, Human_Player, AI_Player, Negamax

    class GameOfBones( 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 = players
            self.pile = 20 # start with 20 bones in the pile
            self.current_player = 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:

.. code:: python

    from easyAI import solve_with_iterative_deepening
    r,d,m = solve_with_iterative_deepening(
        game=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 speed up using a transposition table which will store the situations encountered and the best moves for each:

.. code:: python

    tt = TranspositionTable()
    GameOfBones.ttentry = lambda game : game.pile # key for the table
    r,d,m = solve_with_iterative_deepening(
        game=GameOfBones(),
        ai_depths=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. 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 on Github_.

Maintainers
-----------

- Zulko_ (owner)
- JohnAD_


.. _here: http://zulko.github.io/easyAI
.. _Wikipedia: http://en.wikipedia.org/wiki/Negamax
.. _Zulko : https://github.com/Zulko
.. _JohnAD : https://github.com/JohnAD
.. _Github :  https://github.com/Zulko/easyAI


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "easyAI",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "board games AI artificial intelligence negamax",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/5f/f2/0f799df322bdeffd2dca758c9b64905b8cc7a27415701b751f415a81180b/easyAI-2.0.12.tar.gz",
    "platform": "",
    "description": "easyAI\n======\n\nEasyAI (full documentation here_) is a pure-Python artificial intelligence framework for two-players abstract games such as Tic Tac Toe, Connect 4, Reversi, etc.\nIt makes it easy to define the mechanisms of a game, and play against the computer or solve the game.\nUnder the hood, the AI is a Negamax algorithm with alpha-beta pruning and transposition tables as described on Wikipedia_.\n\n\nInstallation\n------------\n\nIf you have ``pip`` installed, type this in a terminal ::\n\n    sudo pip install easyAI\n\nOtherwise, download the source code (for instance on Github_), unzip everything into one folder and in this folder, in a terminal, type ::\n\n    sudo python setup.py install\n\nAdditionally you will need to install Numpy to be able to run some of the examples.\n\n\nA quick example\n----------------\n\nLet us define the rules of a game and start a match against the AI:\n\n.. code:: python\n\n    from easyAI import TwoPlayerGame, Human_Player, AI_Player, Negamax\n\n    class GameOfBones( TwoPlayerGame ):\n        \"\"\" In turn, the players remove one, two or three bones from a\n        pile of bones. The player who removes the last bone loses. \"\"\"\n\n        def __init__(self, players=None):\n            self.players = players\n            self.pile = 20 # start with 20 bones in the pile\n            self.current_player = 1 # player 1 starts\n\n        def possible_moves(self): return ['1','2','3']\n        def make_move(self,move): self.pile -= int(move) # remove bones.\n        def win(self): return self.pile<=0 # opponent took the last bone ?\n        def is_over(self): return self.win() # Game stops when someone wins.\n        def show(self): print (\"%d bones left in the pile\" % self.pile)\n        def scoring(self): return 100 if game.win() else 0 # For the AI\n\n    # Start a match (and store the history of moves when it ends)\n    ai = Negamax(13) # The AI will think 13 moves in advance \n    game = GameOfBones( [ Human_Player(), AI_Player(ai) ] )\n    history = game.play()\n\nResult: ::\n\n    20 bones left in the pile\n\n    Player 1 what do you play ? 3\n\n    Move #1: player 1 plays 3 :\n    17 bones left in the pile\n\n    Move #2: player 2 plays 1 :\n    16 bones left in the pile\n\n    Player 1 what do you play ?\n\nSolving the game\n*****************\n\nLet us now solve the game:\n\n.. code:: python\n\n    from easyAI import solve_with_iterative_deepening\n    r,d,m = solve_with_iterative_deepening(\n        game=GameOfBones(),\n        ai_depths=range(2,20),\n        win_score=100\n    )\n\nWe 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'``.\n\nThese computations can be speed up using a transposition table which will store the situations encountered and the best moves for each:\n\n.. code:: python\n\n    tt = TranspositionTable()\n    GameOfBones.ttentry = lambda game : game.pile # key for the table\n    r,d,m = solve_with_iterative_deepening(\n        game=GameOfBones(),\n        ai_depths=range(2,20),\n        win_score=100,\n        tt=tt\n    )\n\nAfter 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*:\n\n.. code:: python\n\n    game = GameOfBones( [  AI_Player( tt ), Human_Player() ] )\n    game.play() # you will always lose this game :)\n\n\nContribute !\n------------\n\nEasyAI is an open source software originally written by Zulko_ and 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.\n\nFor troubleshooting and bug reports, the best for now is to ask on Github_.\n\nMaintainers\n-----------\n\n- Zulko_ (owner)\n- JohnAD_\n\n\n.. _here: http://zulko.github.io/easyAI\n.. _Wikipedia: http://en.wikipedia.org/wiki/Negamax\n.. _Zulko : https://github.com/Zulko\n.. _JohnAD : https://github.com/JohnAD\n.. _Github :  https://github.com/Zulko/easyAI\n\n",
    "bugtrack_url": null,
    "license": "LICENSE.txt",
    "summary": "Easy-to-use game AI algorithms (Negamax etc. )",
    "version": "2.0.12",
    "split_keywords": [
        "board",
        "games",
        "ai",
        "artificial",
        "intelligence",
        "negamax"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "0c66a61ce05687f32254fd7a761eac57",
                "sha256": "9ad5444bdc729b60baa39c60d28dd9c677aaec12e27b7972183859f1a0946ee1"
            },
            "downloads": -1,
            "filename": "easyAI-2.0.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0c66a61ce05687f32254fd7a761eac57",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 42174,
            "upload_time": "2021-08-12T12:42:10",
            "upload_time_iso_8601": "2021-08-12T12:42:10.885768Z",
            "url": "https://files.pythonhosted.org/packages/63/2a/927324350557a2da87d59830588ce0c58f67e75384b55af4e82883f0b9cc/easyAI-2.0.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "988b0973c1a1f97f61c337921a2c95e6",
                "sha256": "8c4d2d488bcd81578e1b48d38158bc50353dfd4ab3ab04e4ddac637e08378fbe"
            },
            "downloads": -1,
            "filename": "easyAI-2.0.12.tar.gz",
            "has_sig": false,
            "md5_digest": "988b0973c1a1f97f61c337921a2c95e6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 29263,
            "upload_time": "2021-08-12T12:42:12",
            "upload_time_iso_8601": "2021-08-12T12:42:12.172859Z",
            "url": "https://files.pythonhosted.org/packages/5f/f2/0f799df322bdeffd2dca758c9b64905b8cc7a27415701b751f415a81180b/easyAI-2.0.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-08-12 12:42:12",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "easyai"
}
        
Elapsed time: 0.02171s