Skip to content

Instantly share code, notes, and snippets.

@dat-boris
Created October 10, 2021 03:59
Show Gist options
  • Save dat-boris/5538700853946c210e18a6429cf93074 to your computer and use it in GitHub Desktop.
Save dat-boris/5538700853946c210e18a6429cf93074 to your computer and use it in GitHub Desktop.
Petting Zoo tutorial
"""PettingZoo
Tutorial from: https://nbviewer.org/github/gsverhoeven/gt_rl_course/blob/master/week_8/marl_tictactoe.ipynb
Setup:
pipenv install pettingzoo[classic]
"""
import random
import numpy as np
from collections import defaultdict
from pettingzoo.classic import tictactoe_v3
def policy(observation, agent):
action = random.choice(np.flatnonzero(observation['action_mask']))
return action
env = tictactoe_v3.env()
env.reset()
for i, agent in enumerate(env.agent_iter()):
observation, reward, done, info = env.last()
action = policy(observation, agent) if not done else None
env.step(action)
print("Round {}...".format(i))
env.render() # this visualizes a single game
# TODO: about q learning from the tutorial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment