Skip to main content

A Python library that uses a reinforcement learning AI to play board games such as Chess, Tic Tac Toe, and Reversi.

Project description

plAIer

A Python library that uses a reinforcement learning AI to play board games such as Chess, Tic Tac Toe, and Reversi.

You can also find the project on PyPI

Example of use

# The current game state :
gameState = """
 X | O | 
---+---+---
 O | O | X
---+---+---
 X |   | O
"""

# Import the library :
import plAIer

# Create database if not exists :
plAIer.createDatabase("database_filename.json", "database_name", "description", ["outcomes", "list"])

# Initialize the AI :
outcomesRating = {"O won": 1, "tie": 0, "X won": -1} # The definition of outcomes allows us to determine what the goals of the AI are.
AI = plAIer.Game("database_filename.json", outcomesRating)

# Find the best move in the current game position :
bestMove = AI.findBestMove([
    {"move" : "[0, 2]",
        "stateAfterMove": "\n X | O | O\n---+---+---\n O | O | X\n---+---+---\n X |   | O\n"},
    {"move" : "[2, 1]",
        "stateAfterMove": "\n X | O | \n---+---+---\n O | O | X\n---+---+---\n X | O | O\n"}
])

print(eval(bestMove)) # Output : [2, 1]

# Tell the AI what the outcome of the game is :
AI.setOutcome("O won")

Optimization

For better prediction of the best move to play, please ensure that the format of the given board is always the same. Example with tic-tac-toe :

  • Board 1 : OXO|OXX|XOO ✅
  • Board 2 : XXO|OOO|XOX ✅
  • Board 3 : OOX XOO XXO ❌

Database format

Databases are JSON files which follow this format :

{
    "name": "name of the game",
    "description": "additional informations",
    "outcomes": ["list", "of", "outcomes"],
    "moves": {"gameState1": {"outcome1": 1234, "outcome2": 2345, "outcomeN": 4567},
             "gameState2": {"outcome1": 5678, "outcome2": 6789, "outcomeN": 7890},
             "gameStateN": {"outcome1": 8901, "outcome2": 9011, "outcomeN": 0}
    }
}

How to get it

Write in your terminal (bash or Windows cmd/powershell) the following command :

pip install plAIer

Contribute

Don't hesitate to contribute with pull requests :

  1. Fork the repository
  2. Do your commits
  3. Add your pull request on the repository with a description of what your pull request does

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plaier-1.1.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plAIer-1.1.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file plaier-1.1.2.tar.gz.

File metadata

  • Download URL: plaier-1.1.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for plaier-1.1.2.tar.gz
Algorithm Hash digest
SHA256 730d81552505edc3d6a32e34618d2b02e5a5e1f0a558a5117dd25d6bb6aed38e
MD5 f080966245266d22fcf72992bc9352fc
BLAKE2b-256 c7cbb41c338e41a56b6e54b6e22f2a4da6a3c5e744281bdc91ba71908c4da2c0

See more details on using hashes here.

File details

Details for the file plAIer-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: plAIer-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for plAIer-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 35f5dbfd7b1d1e3e48b88c28a3b15bc58000cc1eda958ecfc81042e48377e40b
MD5 0921ac7418f8d0dc726571140eabbf1e
BLAKE2b-256 2122baf6695ef6fcfb098e429ac0bb9b1a2cf8a45be3f94bfa7aeb06f731e81c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page