Compare commits

..

No commits in common. "b668cf5746a2c2ff17707e23b6c2821f7f54da7a" and "fe6cb991dd7cb80de0ed95815cde13298be370c5" have entirely different histories.

2 changed files with 18 additions and 53 deletions

View File

@ -4,9 +4,7 @@ from gym import spaces
import numpy as np import numpy as np
import pygame import pygame
import random as random_dont_use import random as random_dont_use
from os import urandom
import math import math
from time import time as get_time
from columbus import entities, observables from columbus import entities, observables
@ -46,14 +44,13 @@ class ColumbusEnv(gym.Env):
self.void_damage = 100 self.void_damage = 100
self.rng = random_dont_use.Random() self.rng = random_dont_use.Random()
self._seed(self.env_seed)
self.reset() self.reset()
self.observation_space = self.observable.get_observation_space() self.observation_space = self.observable.get_observation_space()
def _seed(self, seed): def _seed(self, seed):
if seed == None: if seed == None:
seed = urandom(12) seed = random_dont_use.random()
self.rng.seed(seed) self.rng.seed(seed)
def random(self): def random(self):
@ -168,7 +165,6 @@ class ColumbusEnv(gym.Env):
pygame.init() pygame.init()
self._rendered = False self._rendered = False
self.inp = (0.5, 0.5) self.inp = (0.5, 0.5)
self.keypress_timeout = 0
# will get rescaled acording to fps (=reward per second) # will get rescaled acording to fps (=reward per second)
self.new_reward = 0 self.new_reward = 0
self.new_abs_reward = 0 # will not get rescaled. should be used for one-time rewards self.new_abs_reward = 0 # will not get rescaled. should be used for one-time rewards
@ -198,18 +194,6 @@ class ColumbusEnv(gym.Env):
self.joystick_offset[0], 20+int(60*y)+self.joystick_offset[1]), 20, width=0) self.joystick_offset[0], 20+int(60*y)+self.joystick_offset[1]), 20, width=0)
def render(self, mode='human', dont_show=False): def render(self, mode='human', dont_show=False):
for event in pygame.event.get():
pass
keys = pygame.key.get_pressed()
if self.keypress_timeout == 0:
self.keypress_timeout = int(self.fps/2)
if keys[pygame.K_m]:
self.draw_entities = not self.draw_entities
else:
self.keypress_timeout = 0
else:
self.keypress_timeout -= 1
self.visible = self.visible or not dont_show self.visible = self.visible or not dont_show
self._ensure_surface() self._ensure_surface()
pygame.draw.rect(self.surface, (0, 0, 0), pygame.draw.rect(self.surface, (0, 0, 0),
@ -274,9 +258,9 @@ class ColumbusRayDrone(ColumbusTestRay):
class ColumbusCandyland(ColumbusEnv): class ColumbusCandyland(ColumbusEnv):
def __init__(self, observable=observables.RayObservable(chans=[entities.Reward, entities.Void], num_rays=16, include_rand=True), hide_map=False, fps=30, env_seed=None): def __init__(self, observable=observables.RayObservable(chans=[entities.Reward, entities.Void], num_rays=16, include_rand=True), hide_map=False, fps=30):
super(ColumbusCandyland, self).__init__( super(ColumbusCandyland, self).__init__(
observable=observable, fps=fps, env_seed=env_seed) observable=observable, fps=fps)
self.draw_entities = not hide_map self.draw_entities = not hide_map
def setup(self): def setup(self):
@ -294,7 +278,7 @@ class ColumbusCandyland(ColumbusEnv):
class ColumbusEasyObstacles(ColumbusEnv): class ColumbusEasyObstacles(ColumbusEnv):
def __init__(self, observable=observables.RayObservable(num_rays=16), hide_map=False, fps=30, env_seed=None): def __init__(self, observable=observables.RayObservable(num_rays=16), hide_map=False, fps=30, env_seed=None):
super(ColumbusEasyObstacles, self).__init__( super(ColumbusEasyObstacles, self).__init__(
observable=observable, fps=fps, env_seed=env_seed) observable=observable, fps=fps)
self.draw_entities = not hide_map self.draw_entities = not hide_map
self.aux_reward_max = 0.1 self.aux_reward_max = 0.1
@ -310,31 +294,7 @@ class ColumbusEasyObstacles(ColumbusEnv):
self.entities.append(reward) self.entities.append(reward)
for i in range(1): for i in range(1):
enemy = entities.WalkingChaser(self) enemy = entities.WalkingChaser(self)
enemy.chase_speed = 0.20 enemy.chase_speed = 0.1
self.entities.append(enemy)
class ColumbusEasierObstacles(ColumbusEnv):
def __init__(self, observable=observables.RayObservable(num_rays=16), hide_map=False, fps=30, env_seed=None):
super(ColumbusEasierObstacles, self).__init__(
observable=observable, fps=fps, env_seed=env_seed)
self.draw_entities = not hide_map
self.aux_reward_max = 0.5
def setup(self):
self.agent.pos = self.start_pos
for i in range(5):
enemy = entities.CircleBarrier(self)
enemy.radius = 30 + self.random()*70
self.entities.append(enemy)
for i in range(3):
reward = entities.TeleportingReward(self)
reward.radius = 30
reward.reward *= 2
self.entities.append(reward)
for i in range(1):
enemy = entities.WalkingChaser(self)
enemy.chase_speed = 0.20
self.entities.append(enemy) self.entities.append(enemy)
@ -412,9 +372,3 @@ register(
entry_point=ColumbusEasyObstacles, entry_point=ColumbusEasyObstacles,
max_episode_steps=30*60*2, max_episode_steps=30*60*2,
) )
register(
id='ColumbusEasierObstacles-v0',
entry_point=ColumbusEasyObstacles,
max_episode_steps=30*60*2,
)

View File

@ -7,8 +7,8 @@ from observables import Observable, CnnObservable
def main(): def main():
#env = ColumbusTest3_1(fps=30) #env = ColumbusTest3_1()
env = ColumbusEasierObstacles(fps=30) env = ColumbusEasyObstacles(fps=30)
env.start_pos = [0.6, 0.3] env.start_pos = [0.6, 0.3]
playEnv(env) playEnv(env)
env.close() env.close()
@ -22,6 +22,17 @@ def playEnv(env):
t1 = time() t1 = time()
env.render() env.render()
pos = (0.5, 0.5) pos = (0.5, 0.5)
for event in pygame.event.get():
pass
keys = pygame.key.get_pressed()
if to == 0:
to = int(env.fps/2)
if keys[pygame.K_m]:
env.draw_entities = not env.draw_entities
else:
to = 0
else:
to -= 1
pos = pygame.mouse.get_pos() pos = pygame.mouse.get_pos()
pos = (min(max((pos[0]-env.joystick_offset[0]-20)/60, 0), 1), pos = (min(max((pos[0]-env.joystick_offset[0]-20)/60, 0), 1),
min(max((pos[1]-env.joystick_offset[1]-20)/60, 0), 1)) min(max((pos[1]-env.joystick_offset[1]-20)/60, 0), 1))