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.
```python
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.
```python
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.
```python
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.
```python
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__)
```
Object-oriented easy2use solution for interacting with https://battleofai.net/ \'s API.
A short summary of the basic features.
#### Configure your client easily.
```python
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.
```python
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.
```python
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.
```python
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
battleofai-0.1.0.tar.gz
(5.5 kB
view hashes)
Built Distribution
Close
Hashes for battleofai-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e0d5f71c03aca7a29af7a18dab6811f60f66c0e3a55a2c899ba9f644402954f |
|
MD5 | f970b28269368b15c68102a83808bfd2 |
|
BLAKE2b-256 | 98baf2cb83d98b5e1ca47304a052f1fc21f61baf7ba33546776246cee15efffd |