All Projects → ArthurFirmino → gym-battlesnake

ArthurFirmino / gym-battlesnake

Licence: MIT license
Multi-agent reinforcement learning environment

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to gym-battlesnake

omd
JAX code for the paper "Control-Oriented Model-Based Reinforcement Learning with Implicit Differentiation"
Stars: ✭ 43 (+48.28%)
Mutual labels:  gym
GoBigger
Come & try Decision-Intelligence version of "Agar"! Gobigger could also help you with multi-agent decision intelligence study.
Stars: ✭ 410 (+1313.79%)
Mutual labels:  gym
fenics-DRL
Repository from the paper https://arxiv.org/abs/1908.04127, to train Deep Reinforcement Learning in Fluid Mechanics Setup.
Stars: ✭ 40 (+37.93%)
Mutual labels:  gym
Fruit-API
A Universal Deep Reinforcement Learning Framework
Stars: ✭ 61 (+110.34%)
Mutual labels:  multi-agent-reinforcement-learning
malib deprecated
A Multi-agent Learning Framework
Stars: ✭ 63 (+117.24%)
Mutual labels:  multi-agent-reinforcement-learning
safe-control-gym
PyBullet CartPole and Quadrotor environments—with CasADi symbolic a priori dynamics—for learning-based control and RL
Stars: ✭ 272 (+837.93%)
Mutual labels:  gym
Rls
Reinforcement Learning Algorithms Based on TensorFlow 2.x
Stars: ✭ 239 (+724.14%)
Mutual labels:  gym
CommNet-BiCnet
CommNet and BiCnet implementation in tensorflow
Stars: ✭ 50 (+72.41%)
Mutual labels:  multi-agent-reinforcement-learning
freqtrade-gym
A customized gym environment for developing and comparing reinforcement learning algorithms in crypto trading.
Stars: ✭ 192 (+562.07%)
Mutual labels:  gym
CartPole
Run OpenAI Gym on a Server
Stars: ✭ 16 (-44.83%)
Mutual labels:  gym
pytorch-gym
Implementation of the Deep Deterministic Policy Gradient(DDPG) in bullet Gym using pytorch
Stars: ✭ 39 (+34.48%)
Mutual labels:  gym
reinforcement learning ppo rnd
Deep Reinforcement Learning by using Proximal Policy Optimization and Random Network Distillation in Tensorflow 2 and Pytorch with some explanation
Stars: ✭ 33 (+13.79%)
Mutual labels:  gym
ecole
Extensible Combinatorial Optimization Learning Environments
Stars: ✭ 249 (+758.62%)
Mutual labels:  gym
DQN
Deep-Q-Network reinforcement learning algorithm applied to a simple 2d-car-racing environment
Stars: ✭ 42 (+44.83%)
Mutual labels:  gym
gym-cryptotrading
OpenAI Gym Environment API based Bitcoin trading environment
Stars: ✭ 111 (+282.76%)
Mutual labels:  gym
multi car racing
An OpenAI Gym environment for multi-agent car racing based on Gym's original car racing environment.
Stars: ✭ 58 (+100%)
Mutual labels:  gym
ios-build-script
Shell scripts to build ipa
Stars: ✭ 52 (+79.31%)
Mutual labels:  gym
es pytorch
High performance implementation of Deep neuroevolution in pytorch using mpi4py. Intended for use on HPC clusters
Stars: ✭ 20 (-31.03%)
Mutual labels:  gym
flutter
Flutter fitness/workout app for wger
Stars: ✭ 106 (+265.52%)
Mutual labels:  gym
Pytorch-RL-CPP
A Repository with C++ implementations of Reinforcement Learning Algorithms (Pytorch)
Stars: ✭ 73 (+151.72%)
Mutual labels:  gym

Gym-Battlesnake

Gym-Battlesnake is a multi-agent reinforcement learning environment inspired by the annual Battlesnake event held in Victoria, BC each year, and conforming to the OpenAI Gym interface.

Alt Text

Features

  • Multi-threaded game implementation written in fast C++
  • Single agent training with multiple other agents as opponents
  • Render mode available to see your agents play

Installation

Prerequisites

Gym-Battlesnake has only been tested on Ubuntu 18.04. Install the dependencies using the command:

sudo apt-get update && sudo apt-get install cmake libopenmpi-dev python3-dev zlib1g-dev libsfml-dev

You will also need to install tensorflow or tensorflow-gpu (2.0 not tested), see https://www.tensorflow.org/install/pip.

Install using Pip

Clone this repository using the following command:

git clone https://github.com/ArthurFirmino/gym-battlesnake

Change into the directory and install using pip (consider setting up a Python virtual environment first):

cd gym-battlesnake
pip install -e .

Example

Single agent training:

from gym_battlesnake.gymbattlesnake import BattlesnakeEnv
from gym_battlesnake.custompolicy import CustomPolicy
from stable_baselines import PPO2

env = BattlesnakeEnv(n_threads=4, n_envs=16)

model = PPO2(CustomPolicy, env, verbose=1, learning_rate=1e-3)
model.learn(total_timesteps=100000)
model.save('ppo2_trainedmodel')

del model
model = PPO2.load('ppo2_trainedmodel')

obs = env.reset()
for _ in range(10000):
    action,_ = model.predict(obs)
    obs,_,_,_ = env.step(action)
    env.render()

Multi agent training:

from gym_battlesnake.gymbattlesnake import BattlesnakeEnv
from gym_battlesnake.custompolicy import CustomPolicy
from stable_baselines import PPO2

num_agents = 4
placeholder_env = BattlesnakeEnv(n_threads=4, n_envs=16)
models = [PPO2(CustomPolicy, placeholder_env, verbose=1, learning_rate=1e-3) for _ in range(num_agents)]
placeholder_env.close()

for _ in range(10):
    for model in models:
        env = BattlesnakeEnv(n_threads=4, n_envs=16, opponents=[ m for m in models if m is not model])
        model.set_env(env)
        model.learn(total_timesteps=100000)
        env.close()

model = models[0]
env = BattlesnakeEnv(n_threads=1, n_envs=1, opponents=[ m for m in models if m is not model])
obs = env.reset()
for _ in range(10000):
    action,_ = model.predict(obs)
    obs,_,_,_ = env.step(action)
    env.render()

Notes

  • See OpenAI documentation on gym for more details about its interface
  • See stable-baselines documentation for more details on their PPO2 implementation and other suitable algorithms
  • For multi-agent training tensorflow-gpu is recommended, as well as a large number of environments (~100) to maximize data transfer to the GPU.

Contributing

  1. Fork
  2. Clone and Setup
  3. Develop
  4. Pull Request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].