Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions carlo/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ def __init__(self, center: Point, heading: float, color: str = 'red'):
super(Car, self).__init__(center, heading, size, movable, friction)
self.color = color
self.collidable = True

def get_reward(self, collision_exists: bool, reached_goal: bool):
# r = r(s, a)
# - large positive reward for reaching the goal
# - large negative reward for colliding or going off the road
# - small negative reward for every tick we have not reached the goal
r = 0
if collision_exists:
r = r - 1000
elif reached_goal:
r = r + 100000
else:
r = r - 1

return r

class Pedestrian(CircleEntity):
def __init__(self, center: Point, heading: float, color: str = 'LightSalmon3'): # after careful consideration, I decided my color is the same as a salmon, so here we go.
Expand Down
25 changes: 22 additions & 3 deletions simple_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@
w.add(carlo.RectangleBuilding(carlo.Point(40, 70), carlo.Point(15, 2), '#FF6103'))
w.add(carlo.RectangleBuilding(carlo.Point(40, 77), carlo.Point(15, 2), '#FF6103'))

goal = carlo.Painting(carlo.Point(60, 100), carlo.Point(40, 1), 'green')

w.add(goal) # We build a goal.

# A Car object is a dynamic object -- it can move. We construct it using its center location and heading angle.
c1 = carlo.Car(carlo.Point(40,10), np.pi/2)
w.add(c1)
c1.set_control(0, 0.55)
c1.set_control(0.0, 0.55)
# TODO: make this a constant size to run faster
r1 = []

c2 = carlo.Car(carlo.Point(60,10), np.pi/2, 'blue')
w.add(c2)
Expand All @@ -39,10 +45,23 @@
w.render()
w.tick()
time.sleep(dt/4)

c1_collided = w.collision_exists(c1)
c2_collided = w.collision_exists(c2)
c1_reached_goal = c1.collidesWith(goal)
r1.append(c1.get_reward(c1_collided, c1_reached_goal))

print(c1.center)

print("Reward: ", c1.get_reward(c1_collided, c1_reached_goal))

# print("Red car position: ", c1.center)
if w.collision_exists(c1):
if c1_collided:
print('Red car collided with something...')
if w.collision_exists(c2):
if c2_collided:
print('Blue car collided with something...')
if c1_reached_goal:
print('Red car reached goal')