Fixed bugs
parent
ce02009d64
commit
1216378c49
|
@ -49,6 +49,8 @@ class Celeste:
|
|||
|
||||
# Initialize variables
|
||||
self.internal_status = {}
|
||||
self.before_out = None
|
||||
self.last_point_frame = 0
|
||||
|
||||
# Score system
|
||||
self.frame_counter = 0
|
||||
|
@ -166,6 +168,9 @@ class Celeste:
|
|||
self.internal_status = {}
|
||||
self.next_point = 0
|
||||
self.frame_counter = 0
|
||||
self.before_out = None
|
||||
self.resetting = True
|
||||
self.last_point_frame = 0
|
||||
|
||||
self.keypress("Escape")
|
||||
self.keystring("run")
|
||||
|
@ -185,13 +190,12 @@ class Celeste:
|
|||
# Get state, call callback, wait for state
|
||||
# One line => one frame.
|
||||
|
||||
before_out = None
|
||||
|
||||
it = iter(self.process.stdout.readline, "")
|
||||
|
||||
|
||||
for line in it:
|
||||
l = line.decode("utf-8")[:-1].strip()
|
||||
self.resetting = False
|
||||
|
||||
# This should only occur at game start
|
||||
if l in ["!RESTART"]:
|
||||
|
@ -221,6 +225,7 @@ class Celeste:
|
|||
if dist <= 4 and y == ty:
|
||||
print(f"Got point {self.next_point}")
|
||||
self.next_point += 1
|
||||
self.last_point_frame = self.frame_counter
|
||||
|
||||
# Recalculate distance to new point
|
||||
tx, ty = self.target_points[self.status["stage"]][self.next_point]
|
||||
|
@ -229,9 +234,14 @@ class Celeste:
|
|||
(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
|
||||
|
||||
# Call step callback
|
||||
if before_out is not None:
|
||||
after(self, before_out)
|
||||
before_out = before(self)
|
||||
# Call step callbacks
|
||||
if self.before_out is not None:
|
||||
after(self, self.before_out)
|
||||
if not self.resetting:
|
||||
self.before_out = before(self)
|
|
@ -362,10 +362,18 @@ def on_state_after(celeste, before_out):
|
|||
|
||||
if state["next_point"] == next_state["next_point"]:
|
||||
reward = state["dist"] - next_state["dist"]
|
||||
|
||||
if reward > 0:
|
||||
reward = 1
|
||||
elif reward < 0:
|
||||
reward = -1
|
||||
else:
|
||||
reward = 0
|
||||
else:
|
||||
# Score for reaching a point
|
||||
reward = 10
|
||||
|
||||
|
||||
pt_reward = torch.tensor([reward], device = compute_device)
|
||||
|
||||
|
||||
|
|
Reference in New Issue