Mark
/
celeste-ai
Archived
1
0
Fork 0

Added configurable checkpoints and better stage complete handling

master
Mark 2023-02-26 12:10:11 -08:00
parent 0b61702677
commit 03135e2ef9
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 63 additions and 41 deletions

View File

@ -77,14 +77,17 @@ class Celeste:
# Targets the agent tries to reach. # Targets the agent tries to reach.
# The last target MUST be outside the frame. # The last target MUST be outside the frame.
# Format is X, Y, range, force_y
# force_y is optional. If true, y_value MUST match perfectly.
target_checkpoints = [ target_checkpoints = [
[ # Stage 1 [ # Stage 1
#(28, 88), # Start pillar #(28, 88, 8), # Start pillar
(60, 80), # Middle pillar (60, 80, 8), # Middle pillar
(105, 64), # Right ledge (105, 64, 8), # Right ledge
(25, 40), # Left ledge (25, 40, 8), # Left ledge
(110, 16), # End ledge (97, 24, 5, True), # Small end ledge
(110, -2), # Next stage (110, 16, 8), # End ledge
(110, -20, 8), # Next stage
] ]
] ]
@ -208,9 +211,9 @@ class Celeste:
[int(self._internal_state["rx"])] [int(self._internal_state["rx"])]
) )
if len(Celeste.target_checkpoints) < stage: if len(Celeste.target_checkpoints) <= stage:
next_point_x = None next_point_x = 0
next_point_y = None next_point_y = 0
else: else:
next_point_x = Celeste.target_checkpoints[stage][self._next_checkpoint_idx][0] next_point_x = Celeste.target_checkpoints[stage][self._next_checkpoint_idx][0]
next_point_y = Celeste.target_checkpoints[stage][self._next_checkpoint_idx][1] next_point_y = Celeste.target_checkpoints[stage][self._next_checkpoint_idx][1]
@ -329,7 +332,7 @@ class Celeste:
if self.state.stage <= 0:
# Calculate distance to each point # Calculate distance to each point
x = self.state.xpos x = self.state.xpos
y = self.state.ypos y = self.state.ypos
@ -340,7 +343,7 @@ class Celeste:
continue continue
# Update checkpoints # Update checkpoints
tx, ty = c tx, ty = c[:2]
dist[i] = (math.sqrt( dist[i] = (math.sqrt(
(x-tx)*(x-tx) + (x-tx)*(x-tx) +
((y-ty)*(y-ty))/2 ((y-ty)*(y-ty))/2
@ -351,13 +354,32 @@ class Celeste:
dist = int(dist[min_idx]) dist = int(dist[min_idx])
if dist <= 8: t = Celeste.target_checkpoints[self.state.stage][min_idx]
print(f"Got point {min_idx}") range = t[2]
if len(t) == 3:
force_y = False
else:
force_y = t[3]
if force_y:
got_point = (
dist <= range and
y == t[1]
)
else:
got_point = dist <= range
if got_point:
self._next_checkpoint_idx = min_idx + 1 self._next_checkpoint_idx = min_idx + 1
self._last_checkpoint_state = self._state_counter self._last_checkpoint_state = self._state_counter
# Recalculate distance to new point # Recalculate distance to new point
tx, ty = Celeste.target_checkpoints[self.state.stage][self._next_checkpoint_idx] tx, ty = (
Celeste.target_checkpoints
[self.state.stage]
[self._next_checkpoint_idx]
[:2]
)
dist = math.sqrt( dist = math.sqrt(
(x-tx)*(x-tx) + (x-tx)*(x-tx) +
((y-ty)*(y-ty))/2 ((y-ty)*(y-ty))/2