Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcarthur committed Aug 17, 2020
0 parents commit 85b10eb
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_STORE
Empty file added README.md
Empty file.
6 changes: 6 additions & 0 deletions gym_risk/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from gym.envs.registration import register

register(
id='risk-v0',
entry_point='gym_risk.envs:RiskEnv',
)
1 change: 1 addition & 0 deletions gym_risk/assets/us_cont_graph.json

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions gym_risk/assets/us_states.json

Large diffs are not rendered by default.

Binary file added gym_risk/assets/us_states_shp.zip
Binary file not shown.
1 change: 1 addition & 0 deletions gym_risk/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from gym_risk.envs.risk_env import RiskEnv
60 changes: 60 additions & 0 deletions gym_risk/envs/risk_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import gym

class RiskEnv(gym.Env):
metadata = {'render.modes': ['human']}

def __init__(self):
pass

def _step(self, action):
"""
Parameters
----------
action :
Returns
-------
ob, reward, episode_over, info : tuple
ob (object) :
an environment-specific object representing your observation of
the environment.
reward (float) :
amount of reward achieved by the previous action. The scale
varies between environments, but the goal is always to increase
your total reward.
episode_over (bool) :
whether it's time to reset the environment again. Most (but not
all) tasks are divided up into well-defined episodes, and done
being True indicates the episode has terminated. (For example,
perhaps the pole tipped too far, or you lost your last life.)
info (dict) :
diagnostic information useful for debugging. It can sometimes
be useful for learning (for example, it might contain the raw
probabilities behind the environment's last state change).
However, official evaluations of your agent are not allowed to
use this for learning.
"""
self._take_action(action)
self.status = self.env.step()
reward = self._get_reward()
ob = self.env.getState()
episode_over = self.status != hfo_py.IN_GAME
return ob, reward, episode_over, {}

def _reset(self):
pass

def _render(self, mode='human', close=False):
pass

def _take_action(self, action):
pass

def _get_reward(self):
""" Reward is given for XY. """
if self.status == FOOBAR:
return 1
elif self.status == ABC:
return self.somestate ** 2
else:
return 0
24 changes: 24 additions & 0 deletions gym_risk/map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import random
import networkx as nx

from maps.debug import debug

class Map():
metadata = {}

def __init__(self):
self.graph = None
pass

def initialize_player_assignment(self):
"""Randomly assigns each player a country until there are none left"""


pass

def change_ownership(self, payload):
"""Change ownership of a country
Params: payload (dict) {node:player}
"""
nx.set_node_attributes(self.graph, payload, "owner")
pass
17 changes: 17 additions & 0 deletions gym_risk/maps/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import networkx as nx

debug = nx.Graph()

debug.add_node("Thousand Oaks", continent="California", color="red")
debug.add_node("San Francisco", continent="California", color="red")
debug.add_node("Sacramento", continent="California", color="red")
debug.add_node("Provo", continent="Utah", color="blue")
debug.add_node("South Jordan", continent="Utah", color="blue")

debug.add_edge("South Jordan", "Provo")
debug.add_edge("South Jordan", "San Francisco")
debug.add_edge("Thousand Oaks", "San Francisco")
debug.add_edge("Provo", "San Francisco")
debug.add_edge("San Francisco", "Sacramento")
debug.add_edge("Sacramento", "Thousand Oaks")
debug.add_edge("Sacramento", "Provo")
4 changes: 4 additions & 0 deletions gym_risk/viz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### File for visualizing the map
from matplotlib import pyplot as plt
import networkx as nx

10 changes: 10 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from setuptools import setup

setup(name='gym_risk',
version='0.0.1',
install_requires=['gym',
'networkx',
'geopandas',
'descartes',
] # And any other dependencies risk needs
)

0 comments on commit 85b10eb

Please sign in to comment.