Skip to main content

A wrapper for the battleofai API.

Project description

Battle of AI - Python library

Object-oriented easy2use solution for interacting with https://battleofai.net/ 's API.

A short summary of the basic features.

Configure your client easily.

from battleofai import Client

client = Client(credentials=('username', 'password'))

# if you want to export your config
client.config.from_python_file('config.py')

# or use json
client.config.from_json_file('config.json')

Play games automatically.

from battleofai import Client, Core


client = Client()  # specify credentials


@client.callback()
def turn(board, symbol):
    for x_pos, columns in enumerate(board):
        for y_pos, field in enumerate(columns):
            if field == '#':  # if position is free
                return x_pos, y_pos  # set my stone


client.play(Core)

Play games manually.

from battleofai import Client, Core, GameState
import time


client = Client()  # specify credentials


def turn(board, symbol):
    for x_pos, columns in enumerate(board):
        for y_pos, field in enumerate(columns):
            if field == '#':  # if position is free
                return x_pos, y_pos  # set my stone


game = Core.create_game()

client.login()

my_match = Core(callback=turn)
my_match.join_game(client, game)

# then either
my_match.play()

# or even something like this
playing = True
while playing:
    game.update()

    if not game.state == GameState.STARTED:
        break

    if my_match.is_active:
        resp = my_match.make_turn()

        if resp.status_code == 200 and 'false' in resp.text:
            playing = False

    time.sleep(5)

Manage games.

from battleofai import Game, GameState, Core

my_game = Game.get(game_id=100)
print(my_game.players)

open_games = Game.list(game_state=GameState.WAITING)

new_game = Game.create(Core.__game_name__)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

battleofai-0.1.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file battleofai-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: battleofai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for battleofai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d22043476730bdc2831c851146997e83375ca8726cc94d2113fd480d8e51601a
MD5 d40c7dd8d07260cde57203b13b1745d8
BLAKE2b-256 c4226093434e35e6bf77b6fb4d1434ea6fd90d19c27fe6d3367217565ecea7d4

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