Skip to content
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.

LiBa001/python-battleofai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: MIT

Battle of AI - Python library

PyPI version Build Status

DEPRECATED: The Battle of AI has been taken offline by it's creators

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__)