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,46 +332,65 @@ class Celeste:
if self.state.stage <= 0:
# Calculate distance to each point
x = self.state.xpos
y = self.state.ypos
dist = np.zeros(len(Celeste.target_checkpoints[self.state.stage]), dtype=np.float16)
for i, c in enumerate(Celeste.target_checkpoints[self.state.stage]):
if i < self._next_checkpoint_idx:
dist[i] = 1000
continue
# Calculate distance to each point # Update checkpoints
x = self.state.xpos tx, ty = c[:2]
y = self.state.ypos dist[i] = (math.sqrt(
dist = np.zeros(len(Celeste.target_checkpoints[self.state.stage]), dtype=np.float16) (x-tx)*(x-tx) +
for i, c in enumerate(Celeste.target_checkpoints[self.state.stage]): ((y-ty)*(y-ty))/2
if i < self._next_checkpoint_idx: # Possible modification:
dist[i] = 1000 # make x-distance twice as valuable as y-distance
continue ))
min_idx = int(dist.argmin())
dist = int(dist[min_idx])
# Update checkpoints
tx, ty = c t = Celeste.target_checkpoints[self.state.stage][min_idx]
dist[i] = (math.sqrt( range = t[2]
(x-tx)*(x-tx) + if len(t) == 3:
((y-ty)*(y-ty))/2 force_y = False
# Possible modification: else:
# make x-distance twice as valuable as y-distance force_y = t[3]
))
min_idx = int(dist.argmin())
dist = int(dist[min_idx])
if force_y:
got_point = (
dist <= range and
y == t[1]
)
else:
got_point = dist <= range
if dist <= 8: if got_point:
print(f"Got point {min_idx}") 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 = (
dist = math.sqrt( Celeste.target_checkpoints
(x-tx)*(x-tx) + [self.state.stage]
((y-ty)*(y-ty))/2 [self._next_checkpoint_idx]
) [:2]
)
dist = math.sqrt(
(x-tx)*(x-tx) +
((y-ty)*(y-ty))/2
)
# Timeout if we spend too long between points # Timeout if we spend too long between points
elif self._state_counter - self._last_checkpoint_state > self.state_timeout: elif self._state_counter - self._last_checkpoint_state > self.state_timeout:
self._internal_state["dc"] = str(int(self._internal_state["dc"]) + 1) self._internal_state["dc"] = str(int(self._internal_state["dc"]) + 1)
self._dist = dist self._dist = dist
# Call step callbacks # Call step callbacks
# These should call celeste.act() to set next input # These should call celeste.act() to set next input