Compare commits
3 Commits
2132deedcd
...
bb006eceb0
Author | SHA1 | Date | |
---|---|---|---|
bb006eceb0 | |||
4cd64a6fbd | |||
7113190e35 |
@ -166,6 +166,7 @@ class ColumbusEnv(gym.Env):
|
|||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
self._seed(self.env_seed)
|
||||||
self._rendered = False
|
self._rendered = False
|
||||||
self.inp = (0.5, 0.5)
|
self.inp = (0.5, 0.5)
|
||||||
self.keypress_timeout = 0
|
self.keypress_timeout = 0
|
||||||
@ -178,7 +179,6 @@ class ColumbusEnv(gym.Env):
|
|||||||
self.agent = entities.Agent(self)
|
self.agent = entities.Agent(self)
|
||||||
self.setup()
|
self.setup()
|
||||||
self.entities.append(self.agent) # add it last, will be drawn on top
|
self.entities.append(self.agent) # add it last, will be drawn on top
|
||||||
self._seed(self.env_seed)
|
|
||||||
self.observable._entities = None
|
self.observable._entities = None
|
||||||
return self.observable.get_observation()
|
return self.observable.get_observation()
|
||||||
|
|
||||||
@ -206,6 +206,8 @@ class ColumbusEnv(gym.Env):
|
|||||||
self.keypress_timeout = int(self.fps/2)
|
self.keypress_timeout = int(self.fps/2)
|
||||||
if keys[pygame.K_m]:
|
if keys[pygame.K_m]:
|
||||||
self.draw_entities = not self.draw_entities
|
self.draw_entities = not self.draw_entities
|
||||||
|
elif keys[pygame.K_r]:
|
||||||
|
self.reset()
|
||||||
else:
|
else:
|
||||||
self.keypress_timeout = 0
|
self.keypress_timeout = 0
|
||||||
else:
|
else:
|
||||||
@ -361,7 +363,7 @@ class ColumbusJustState(ColumbusEnv):
|
|||||||
|
|
||||||
|
|
||||||
class ColumbusStateWithBarriers(ColumbusEnv):
|
class ColumbusStateWithBarriers(ColumbusEnv):
|
||||||
def __init__(self, observable=observables.StateObservable(coordsAgent=True, speedAgent=False, coordsRelativeToAgent=False, coordsRewards=True, rewardsWhitelist=None, coordsEnemys=True, enemysWhitelist=None, enemysNoBarriers=True, rewardsTimeouts=False, include_rand=True), fps=30, env_seed=3.1):
|
def __init__(self, observable=observables.StateObservable(coordsAgent=True, speedAgent=False, coordsRelativeToAgent=False, coordsRewards=True, rewardsWhitelist=None, coordsEnemys=True, enemysWhitelist=None, enemysNoBarriers=True, rewardsTimeouts=False, include_rand=True), fps=30, env_seed=3.141):
|
||||||
super(ColumbusStateWithBarriers, self).__init__(
|
super(ColumbusStateWithBarriers, self).__init__(
|
||||||
observable=observable, fps=fps, env_seed=env_seed)
|
observable=observable, fps=fps, env_seed=env_seed)
|
||||||
self.aux_reward_max = 0.01
|
self.aux_reward_max = 0.01
|
||||||
@ -373,9 +375,9 @@ class ColumbusStateWithBarriers(ColumbusEnv):
|
|||||||
enemy = entities.CircleBarrier(self)
|
enemy = entities.CircleBarrier(self)
|
||||||
enemy.radius = self.random()*25+75
|
enemy.radius = self.random()*25+75
|
||||||
self.entities.append(enemy)
|
self.entities.append(enemy)
|
||||||
for i in range(3):
|
for i in range(1):
|
||||||
enemy = entities.FlyingChaser(self)
|
enemy = entities.FlyingChaser(self)
|
||||||
enemy.chase_acc = self.random()*0.4+0.3 # *0.6+0.5
|
enemy.chase_acc = 0.55 # *0.6+0.5
|
||||||
self.entities.append(enemy)
|
self.entities.append(enemy)
|
||||||
for i in range(1):
|
for i in range(1):
|
||||||
reward = entities.TeleportingReward(self)
|
reward = entities.TeleportingReward(self)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from time import sleep, time
|
from time import sleep, time
|
||||||
from env import *
|
import env
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
@ -7,13 +7,37 @@ from observables import Observable, CnnObservable
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
#env = ColumbusTest3_1(fps=30)
|
Env = chooseEnv()
|
||||||
env = ColumbusStateWithBarriers(fps=30)
|
env = Env(fps=30)
|
||||||
env.start_pos = [0.6, 0.3]
|
env.start_pos = [0.6, 0.3]
|
||||||
playEnv(env)
|
playEnv(env)
|
||||||
env.close()
|
env.close()
|
||||||
|
|
||||||
|
|
||||||
|
def getAvaibleEnvs():
|
||||||
|
# kinda hacky... idk
|
||||||
|
strs = dir(env)
|
||||||
|
for s in strs:
|
||||||
|
if s.startswith('Columbus') and s != 'ColumbusEnv':
|
||||||
|
yield getattr(env, s)
|
||||||
|
|
||||||
|
|
||||||
|
def chooseEnv():
|
||||||
|
envs = list(getAvaibleEnvs())
|
||||||
|
for i, Env in enumerate(envs):
|
||||||
|
print('['+str(i)+'] '+Env.__name__)
|
||||||
|
while True:
|
||||||
|
inp = input('[#> ')
|
||||||
|
try:
|
||||||
|
i = int(inp)
|
||||||
|
except:
|
||||||
|
print('[!] You have to enter the number...')
|
||||||
|
if i < 0 or i >= len(envs):
|
||||||
|
print(
|
||||||
|
'[!] That is a number, but not one that makes sense in this context...')
|
||||||
|
return envs[i]
|
||||||
|
|
||||||
|
|
||||||
def playEnv(env):
|
def playEnv(env):
|
||||||
env.reset()
|
env.reset()
|
||||||
done = False
|
done = False
|
||||||
|
@ -58,10 +58,10 @@ class CnnObservable(Observable):
|
|||||||
snap = self.env.surface.subsurface(rect)
|
snap = self.env.surface.subsurface(rect)
|
||||||
self.snap = pygame.Surface((self.in_width, self.in_height))
|
self.snap = pygame.Surface((self.in_width, self.in_height))
|
||||||
if self.env.void_barrier:
|
if self.env.void_barrier:
|
||||||
col = (223, 0, 0)
|
col = (255, 0, 0)
|
||||||
else:
|
else:
|
||||||
col = (50, 50, 50)
|
col = (50, 50, 50)
|
||||||
pygame.draw.rect(self.snap, (50, 50, 50),
|
pygame.draw.rect(self.snap, col,
|
||||||
pygame.Rect(0, 0, self.in_width, self.in_height))
|
pygame.Rect(0, 0, self.in_width, self.in_height))
|
||||||
self.snap.blit(snap, (cx - x, cy - y))
|
self.snap.blit(snap, (cx - x, cy - y))
|
||||||
self.obs = self.scaler(
|
self.obs = self.scaler(
|
||||||
|
Loading…
Reference in New Issue
Block a user