Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

aiarena/rust-arenaclient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust-arenaclient

rust-arenaclient was created for ai-arena to act as a proxy between bots and StarCraft II. It was originally written entirely in Python, but due to performance concerns, was rewritten using Rust + pyo3.

It can be used as a stand-alone binary or as a Python library for convenience.

Installation

You can install rust_arenaclient using:

pip install rust_arenaclient

or alternatively build a binary from source using

cargo build --bin rust_ac_bin

Usage

Python

from rust_ac import Server

server = Server("127.0.0.1:8642")
server.run()

Binary

Currently the proxy server starts on 127.0.0.1:8642 when launched. Future updates will enable the user to specify host and port using command line arguments, after which this README will be updated.

Running a game

rust_arenaclient was made for the purpose of being part of a bigger system to run StarCraft II games. The system will interact with the rust_arenaclient through websockets and is known as a supervisor. rust_arenaclient only acts as a proxy between bots and StarCraft II. The starting of bots and creating game config is the supervisor's job. Example of an extremely basic supervisor script in Python:

import os, subprocess, asyncio, aiohttp
from rust_ac import Server

from rust_ac.match_runner import MatchRunner
from rust_ac import GameConfig


m = MatchRunner(bot_directory=r"D:\desktop backup\aiarenaclient\aiarena-client\aiarena-test-bots")
result = m.run_game(game=GameConfig('AutomatonLE', 'loser_bot', 'MicroMachine'))  # One game

games = [GameConfig('AutomatonLE', 'loser_bot', 'basic_bot') for _ in range(20)]

results = m.run_games_multiple(games=games, instances=3)  # Multiple games - Run 3 games at a time

Logging

Logging is done via the handly pyo3-log crate. To get the Rust logs in Python, initialize the logging library before importing rust-arenaclient, i.e.

import os, subprocess, asyncio, aiohttp
import logging # Needs to be imported before importing rust_ac
logging.getLogger().setLevel(logging.DEBUG) # Set debugging level
logging.basicConfig(filename="log.txt", level=logging.DEBUG, filemode="w+") # Write logs to a file called "log.txt"
logging.info("") # Needed to initialize logging
from rust_ac import Server

from rust_ac.match_runner import MatchRunner
from rust_ac import GameConfig


m = MatchRunner(bot_directory=r"D:\desktop backup\aiarenaclient\aiarena-client\aiarena-test-bots")
...

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

GNU GPLv3