Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
markub3327 committed Feb 27, 2024
1 parent 30ac897 commit 698f1b3
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions flappy_bird_gymnasium/envs/flappy_bird_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,25 +272,29 @@ def step(
# find ray closest to the obstacle
min_index = np.argmin(obs)
min_value = obs[min_index] * LIDAR_MAX_DISTANCE
mean_value = np.mean(obs) * LIDAR_MAX_DISTANCE
if "pipe_mean_value" in self._statistics:
self._statistics["pipe_mean_value"] = self._statistics["pipe_mean_value"] * 0.99 + (np.mean(obs) * LIDAR_MAX_DISTANCE) * (1 - 0.99)
else:
self._statistics["pipe_mean_value"] = np.mean(obs) * LIDAR_MAX_DISTANCE

# In the gap
if ((self._player_x + PLAYER_WIDTH) - up_pipe['x']) >= 0 and (self._player_x - up_pipe['x']) <= PIPE_WIDTH:
if "pipe_min_value" in self._nearest_stats:
if min_value < self._nearest_stats["pipe_min_value"]:
self._nearest_stats["pipe_min_value"] = min_value
# print(f"NEAREST TO PIPE !!!: obs: [{min_index}, {min_value}, {mean_value}], up_pipe: [{up_pipe['x']}, {up_pipe['y']+PIPE_HEIGHT}], low_pipe: {low_pipe}, player: [{self._player_x}, {self._player_y}]")
if "pipe_min_value" in self._statistics:
if min_value < self._statistics["pipe_min_value"]:
self._statistics["pipe_min_value"] = min_value
self._statistics["pipe_min_index"] = min_index
# print(f"NEAREST TO PIPE !!!: obs: [{min_index}, {min_value}, {self._statistics['pipe_mean_value']}], up_pipe: [{up_pipe['x']}, {up_pipe['y']+PIPE_HEIGHT}], low_pipe: {low_pipe}, player: [{self._player_x}, {self._player_y}]")
else:
self._nearest_stats["pipe_min_value"] = min_value
self._statistics["pipe_min_value"] = min_value

# Nearest to the ground
diff = np.abs(self._player_y - self._ground['y'])
if "ground_min_value" in self._nearest_stats:
if diff < self._nearest_stats["ground_min_value"]:
self._nearest_stats["ground_min_value"] = diff
# print(f"NEAREST TO GROUND !!!: obs: [{min_index}, {min_value}, {mean_value}], up_pipe: [{up_pipe['x']}, {up_pipe['y']+PIPE_HEIGHT}], low_pipe: {low_pipe}, player: [{self._player_x}, {self._player_y}], Ground: {self._player_y - self._ground['y']}")
if "ground_min_value" in self._statistics:
if diff < self._statistics["ground_min_value"]:
self._statistics["ground_min_value"] = diff
# print(f"NEAREST TO GROUND !!!: obs: [{min_index}, {min_value}, {self._statistics['pipe_mean_value']}], up_pipe: [{up_pipe['x']}, {up_pipe['y']+PIPE_HEIGHT}], low_pipe: {low_pipe}, player: [{self._player_x}, {self._player_y}], Ground: {diff}")
else:
self._nearest_stats["ground_min_value"] = diff
self._statistics["ground_min_value"] = diff


# agent touch the top of the screen as punishment
Expand All @@ -304,14 +308,14 @@ def step(
terminal = True
self._player_vel_y = 0
if self._debug:
if (((self._player_x + PLAYER_WIDTH) - up_pipe['x']) > 0
if (((self._player_x + PLAYER_WIDTH) - up_pipe['x']) >= (0 + (PLAYER_WIDTH / 3))
and (self._player_x - up_pipe['x']) <= (PIPE_WIDTH - (PLAYER_WIDTH / 3))):
print("BETWEEN PIPES")
elif ((self._player_x + PLAYER_WIDTH) - up_pipe['x']) <= 0:
elif ((self._player_x + PLAYER_WIDTH) - up_pipe['x']) < (0 + (PLAYER_WIDTH / 3)):
print("IN FRONT OF")
elif (self._player_x - up_pipe['x']) > (PIPE_WIDTH - (PLAYER_WIDTH / 3)):
print("BEHIND")
print(f"obs: [{min_index}, {min_value}, {mean_value}], Ground: {self._player_y - self._ground['y']}")
print(f"obs: [{self._statistics['pipe_min_index']}, {self._statistics['pipe_min_value']}, {self._statistics['pipe_mean_value']}], Ground: {self._statistics['ground_min_value']}")

info = {"score": self._score}

Expand All @@ -337,7 +341,7 @@ def reset(self, seed=None, options=None):
self._score = 0

if self._debug:
self._nearest_stats = {}
self._statistics = {}

# Generate 3 new pipes to add to upper_pipes and lower_pipes lists
new_pipe1 = self._get_random_pipe()
Expand Down

0 comments on commit 698f1b3

Please sign in to comment.