fixed flower collision
This commit is contained in:
parent
69e03cd3f7
commit
ad2fa2aff9
|
|
@ -191,6 +191,8 @@ class FlowerGameEnv(gym.Env):
|
||||||
self.contact_cooldown_frames = 8
|
self.contact_cooldown_frames = 8
|
||||||
self._cooldown = 0
|
self._cooldown = 0
|
||||||
self.prev_dist_to_flower_nd = None
|
self.prev_dist_to_flower_nd = None
|
||||||
|
self.prev_flower_x = None
|
||||||
|
self.prev_flower_y = None
|
||||||
self.flowers_eaten = 0
|
self.flowers_eaten = 0
|
||||||
|
|
||||||
# Bomben-Filter (konstant, bis auf min_area -> wird aus frac abgeleitet)
|
# Bomben-Filter (konstant, bis auf min_area -> wird aus frac abgeleitet)
|
||||||
|
|
@ -224,14 +226,14 @@ class FlowerGameEnv(gym.Env):
|
||||||
return obs, {}
|
return obs, {}
|
||||||
|
|
||||||
def step(self, action):
|
def step(self, action):
|
||||||
if action == 0:
|
# if action == 0:
|
||||||
pyautogui.press("w")
|
# pyautogui.press("w")
|
||||||
elif action == 1:
|
# elif action == 1:
|
||||||
pyautogui.press("a")
|
# pyautogui.press("a")
|
||||||
elif action == 2:
|
# elif action == 2:
|
||||||
pyautogui.press("s")
|
# pyautogui.press("s")
|
||||||
elif action == 3:
|
# elif action == 3:
|
||||||
pyautogui.press("d")
|
# pyautogui.press("d")
|
||||||
|
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
|
@ -354,19 +356,23 @@ class FlowerGameEnv(gym.Env):
|
||||||
else:
|
else:
|
||||||
self.prev_dist_to_flower_nd = None
|
self.prev_dist_to_flower_nd = None
|
||||||
|
|
||||||
# Eat-Event (achsenweise Rechtecktest, Halbachsen = */2 von w bzw. h)
|
# Eat-Event (Wenn die Blume woanders neu spawnt)
|
||||||
if self._cooldown == 0 and tf and ff:
|
if self._cooldown == 0 and tf and ff:
|
||||||
dx_nw = abs(tx - fx) / float(w if w > 0 else 1)
|
if self.prev_flower_x is None:
|
||||||
dy_nh = abs(ty - fy) / float(h if h > 0 else 1)
|
self.prev_flower_x = fx
|
||||||
if (dx_nw <= (self.eat_x_nd * 0.5)) and (dy_nh <= (self.eat_y_nd * 0.5)):
|
if self.prev_flower_y is None:
|
||||||
|
self.prev_flower_y = fy
|
||||||
|
if abs(self.prev_flower_x - fx) >= float(w/20 if w > 0 else 1) and abs(self.prev_flower_y - fy) >= float(h/15 if h > 0 else 1):
|
||||||
print("Blume gegessen!")
|
print("Blume gegessen!")
|
||||||
reward += self.eat_reward
|
reward += self.eat_reward
|
||||||
self._cooldown = self.contact_cooldown_frames
|
self._cooldown = self.contact_cooldown_frames
|
||||||
self.flowers_eaten += 1
|
self.flowers_eaten += 1
|
||||||
|
self.prev_flower_x = fx
|
||||||
|
self.prev_flower_y = fy
|
||||||
|
|
||||||
# Überprüfung auf Kollision mit Bombe / Game Over Screen Farben
|
# Überprüfung auf Kollision mit Bombe / Game Over Screen Farben
|
||||||
rgb_data = self.raw[:, :, :3]
|
rgb_data = self.raw[:, :, :3]
|
||||||
target_color = np.array([113, 110, 83])
|
target_color = np.array([114, 111, 84])
|
||||||
tolerance = 10
|
tolerance = 10
|
||||||
found_blue = np.any(np.all(np.abs(rgb_data - target_color) <= tolerance, axis=-1))
|
found_blue = np.any(np.all(np.abs(rgb_data - target_color) <= tolerance, axis=-1))
|
||||||
if found_blue:
|
if found_blue:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user