Mark
/
celeste-ai
Archived
1
0
Fork 0

Fixed bugs

master
Mark 2023-02-16 13:52:59 -08:00
parent ce02009d64
commit 1216378c49
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
2 changed files with 33 additions and 15 deletions

View File

@ -49,6 +49,8 @@ class Celeste:
# Initialize variables # Initialize variables
self.internal_status = {} self.internal_status = {}
self.before_out = None
self.last_point_frame = 0
# Score system # Score system
self.frame_counter = 0 self.frame_counter = 0
@ -166,6 +168,9 @@ class Celeste:
self.internal_status = {} self.internal_status = {}
self.next_point = 0 self.next_point = 0
self.frame_counter = 0 self.frame_counter = 0
self.before_out = None
self.resetting = True
self.last_point_frame = 0
self.keypress("Escape") self.keypress("Escape")
self.keystring("run") self.keystring("run")
@ -185,13 +190,12 @@ class Celeste:
# Get state, call callback, wait for state # Get state, call callback, wait for state
# One line => one frame. # One line => one frame.
before_out = None
it = iter(self.process.stdout.readline, "") it = iter(self.process.stdout.readline, "")
for line in it: for line in it:
l = line.decode("utf-8")[:-1].strip() l = line.decode("utf-8")[:-1].strip()
self.resetting = False
# This should only occur at game start # This should only occur at game start
if l in ["!RESTART"]: if l in ["!RESTART"]:
@ -221,6 +225,7 @@ class Celeste:
if dist <= 4 and y == ty: if dist <= 4 and y == ty:
print(f"Got point {self.next_point}") print(f"Got point {self.next_point}")
self.next_point += 1 self.next_point += 1
self.last_point_frame = self.frame_counter
# Recalculate distance to new point # Recalculate distance to new point
tx, ty = self.target_points[self.status["stage"]][self.next_point] tx, ty = self.target_points[self.status["stage"]][self.next_point]
@ -229,9 +234,14 @@ class Celeste:
(y-ty)*(y-ty) (y-ty)*(y-ty)
) )
# Timeout if we spend too long between points
elif self.frame_counter - self.last_point_frame > 40:
self.internal_status["dc"] = str(int(self.internal_status["dc"]) + 1)
self.dist = dist self.dist = dist
# Call step callback # Call step callbacks
if before_out is not None: if self.before_out is not None:
after(self, before_out) after(self, self.before_out)
before_out = before(self) if not self.resetting:
self.before_out = before(self)

View File

@ -362,10 +362,18 @@ def on_state_after(celeste, before_out):
if state["next_point"] == next_state["next_point"]: if state["next_point"] == next_state["next_point"]:
reward = state["dist"] - next_state["dist"] reward = state["dist"] - next_state["dist"]
if reward > 0:
reward = 1
elif reward < 0:
reward = -1
else:
reward = 0
else: else:
# Score for reaching a point # Score for reaching a point
reward = 10 reward = 10
pt_reward = torch.tensor([reward], device = compute_device) pt_reward = torch.tensor([reward], device = compute_device)