Skip to content
62 changes: 62 additions & 0 deletions examples/masha_and_zoe_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from rose.common import obstacles, actions

driver_name = "Zoe and Masha"
running = True

# Define valid lane ranges based on the starting position
def get_lane_range(starting_position):
if starting_position == 1:
return 0, 2
elif starting_position == 4:
return 3, 5
else:
# Default to a range that includes only the starting position if not 1 or 4
return starting_position, starting_position

def run(cur_pos_x, cur_pos_y, obs, world, min_x, max_x):
if cur_pos_x == min_x:
return actions.RIGHT
elif cur_pos_x == max_x:
return actions.LEFT
else:
if min_x < cur_pos_x < max_x:
if obs != obstacles.PENGUIN and obs != obstacles.NONE:
next_obs = world.get((cur_pos_x - 1, cur_pos_y - 1))
if next_obs == obstacles.PENGUIN or next_obs == obstacles.NONE:
return actions.LEFT
else:
return actions.NONE
else:
next_obs = world.get((cur_pos_x + 1, cur_pos_y - 1))
if next_obs == obstacles.PENGUIN or next_obs == obstacles.NONE:
return actions.RIGHT
else:
return actions.NONE
else:
return actions.NONE

def drive(world):
cur_pos_x = world.car.x
cur_pos_y = world.car.y

# Determine the lane range based on the starting position
min_x, max_x = get_lane_range(cur_pos_x)

obs = world.get((cur_pos_x, cur_pos_y - 1))
match obs:
case obstacles.NONE:
return actions.NONE
case obstacles.PENGUIN:
return actions.PICKUP
case obstacles.WATER:
return actions.BRAKE
case obstacles.CRACK:
return actions.JUMP
case obstacles.TRASH:
return run(cur_pos_x, cur_pos_y, obs, world, min_x, max_x)
case obstacles.BIKE:
return run(cur_pos_x, cur_pos_y, obs, world, min_x, max_x)
case obstacles.BARRIER:
return run(cur_pos_x, cur_pos_y, obs, world, min_x, max_x)
case _:
return actions.NONE
117 changes: 117 additions & 0 deletions examples/new_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
from rose.common import obstacles, actions
driver_name = "Zoe and Masha"
running = True
def drive(world):
cur_pos_x = world.car.x
cur_pos_y = world.car.y
obs = world.get((cur_pos_x, cur_pos_y - 1))
match obs:
case obstacles.NONE:
return actions.NONE
case obstacles.PENGUIN:
return actions.PICKUP
case obstacles.WATER:
return actions.BRAKE
case obstacles.CRACK:
return actions.JUMP
case obstacles.TRASH:
return actions.NONE
case obstacles.BIKE:
return actions.NONE
case obstacles.BARRIER:
return actions.NONE


# #"""
# This driver does not do any action.
# """
# from rose.common import obstacles, actions # NOQA
#
# driver_name = "No Driver"
#
#
# def drive(world):
# return actions.NONE


from rose.common import obstacles, actions

driver_name = "Zoe and Masha"
running = True


# Define valid lane ranges based on the starting position
def get_lane_range(starting_position):
if starting_position == 1:
return 0, 2
elif starting_position == 4:
return 3, 5
else:
# Default to a range that includes only the starting position if not 1 or 4
return starting_position, starting_position
def penguin_l(cur_pos_x, cur_pos_y, world, min_x, max_x):
next_obs = world.get((cur_pos_x-1, cur_pos_y - 1))
if next_obs == obstacles.PENGUIN:
return actions.LEFT
return actions.NONE


def penguin_r(cur_pos_x, cur_pos_y, world, min_x, max_x):
next_obs = world.get((cur_pos_x +1, cur_pos_y - 1))
if next_obs == obstacles.PENGUIN:
return actions.RIGHT
return actions.NONE

def run(cur_pos_x, cur_pos_y, obs, world, min_x, max_x):
if cur_pos_x == min_x:
return actions.RIGHT
elif cur_pos_x == max_x:
return actions.LEFT
else:
if min_x < cur_pos_x < max_x:
if obs != obstacles.PENGUIN and obs != obstacles.NONE:
next_obs = world.get((cur_pos_x - 1, cur_pos_y - 1))
if next_obs == obstacles.PENGUIN or next_obs == obstacles.NONE:
return actions.LEFT
else:
return actions.NONE
else:
next_obs = world.get((cur_pos_x + 1, cur_pos_y - 1))
if next_obs == obstacles.PENGUIN or next_obs == obstacles.NONE:
return actions.RIGHT
else:
return actions.NONE
else:
return actions.NONE

def drive(world):
cur_pos_x = world.car.x
cur_pos_y = world.car.y

# Determine the lane range based on the starting position
min_x, max_x = get_lane_range(cur_pos_x)

obs = world.get((cur_pos_x, cur_pos_y - 1))
p_act_1 = penguin_l(cur_pos_x,cur_pos_y,world,min_x,max_x)
if p_act_1 != actions.NONE:
return p_act_1
p_act_2 = penguin_r(cur_pos_x, cur_pos_y, world, min_x, max_x)
if p_act_2 != actions.NONE:
return p_act_2
match obs:
case obstacles.NONE:
return actions.NONE
case obstacles.PENGUIN:
return actions.PICKUP
case obstacles.WATER:
return actions.BRAKE
case obstacles.CRACK:
return actions.JUMP
case obstacles.TRASH:
return run(cur_pos_x, cur_pos_y, obs, world, min_x, max_x)
case obstacles.BIKE:
return run(cur_pos_x, cur_pos_y, obs, world, min_x, max_x)
case obstacles.BARRIER:
return run(cur_pos_x, cur_pos_y, obs, world, min_x, max_x)
case _:
return actions.NONE
117 changes: 111 additions & 6 deletions examples/none.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,115 @@
"""
This driver does not do any action.
"""
from rose.common import obstacles, actions # NOQA
from rose.common import obstacles, actions

driver_name = "No Driver"
driver_name = "Zoe and Masha"
running = True

# Define valid lane ranges based on the starting position
def get_lane_range(starting_position):
if starting_position == 1:
return 0, 2
elif starting_position == 4:
return 3, 5
else:
# Default to a range that includes only the starting position if not 1 or 4
return starting_position, starting_position

def run(cur_pos_x, cur_pos_y, obs, world, min_x, max_x):
if cur_pos_x == min_x:
return actions.RIGHT
elif cur_pos_x == max_x:
return actions.LEFT
else:
if min_x < cur_pos_x < max_x:
if obs != obstacles.PENGUIN and obs != obstacles.NONE:
next_obs = world.get((cur_pos_x - 1, cur_pos_y - 1))
if next_obs == obstacles.PENGUIN or next_obs == obstacles.NONE:
return actions.LEFT
else:
return actions.NONE
else:
next_obs = world.get((cur_pos_x + 1, cur_pos_y - 1))
if next_obs == obstacles.PENGUIN or next_obs == obstacles.NONE:
return actions.RIGHT
else:
return actions.NONE
else:
return actions.NONE

def score(obs):
match obs:
case obstacles.NONE:
return 0
case obstacles.PENGUIN:
return 10
case obstacles.WATER:
return 5
case obstacles.CRACK:
return 4
case obstacles.TRASH:
return -10
case obstacles.BIKE:
return -10
case obstacles.BARRIER:
return -10
case _:
return 0

def new(cur_pos_x, cur_pos_y, obs, world, min_x, max_x):
left = [world.get((cur_pos_x - 1, cur_pos_y - 1))]
left.append(score(left[0]))
print(f"Left lane: {left}")

right = [world.get((cur_pos_x + 1, cur_pos_y - 1))]
right.append(score(right[0]))
print(f"Right lane: {right}")

middle = [world.get((cur_pos_x, cur_pos_y - 1))]
middle.append(score(middle[0]))
print(f"Middle lane: {middle}")

best_lane = better(left, right, middle)
if best_lane == left:
return actions.LEFT
elif best_lane == right:
return actions.RIGHT
else: # best_lane == middle
return actions.NONE

def better(left, right, middle):
higher = max(left[1], right[1], middle[1])
if higher == left[1]:
return left
elif higher == right[1]:
return right
elif higher == middle[1]:
return middle
else:
print('fgbfrewrererg')
return middle


def drive(world):
return actions.NONE
cur_pos_x = world.car.x
cur_pos_y = world.car.y

# Determine the lane range based on the starting position
min_x, max_x = get_lane_range(cur_pos_x)

obs = world.get((cur_pos_x, cur_pos_y - 1))
match obs:
case obstacles.NONE:
return actions.NONE
case obstacles.PENGUIN:
return actions.PICKUP
case obstacles.WATER:
return actions.BRAKE
case obstacles.CRACK:
return actions.JUMP
case obstacles.TRASH:
return new(cur_pos_x, cur_pos_y, obs, world, min_x, max_x)
case obstacles.BIKE:
return new(cur_pos_x, cur_pos_y, obs, world, min_x, max_x)
case obstacles.BARRIER:
return new(cur_pos_x, cur_pos_y, obs, world, min_x, max_x)
case _:
return actions.NONE
93 changes: 93 additions & 0 deletions examples/zoe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from none import *


def find_lane(cur_pos_x, cur_pos_y):
min_x, max_x = 0, 2
return min_x, max_x


def count(points, op):
sum_points = 0
for i in points[op]:
sum_points += i

return sum_points


def merge(op_1, op_2, op_3, points):

if op_1 == 'no' and op_2 == 'no' and op_3 == 'no':
return ['no']

if op_1 == 'no' and op_2 == 'no' and op_3 != 'no':
return [op_3]

if op_1 == 'no' and op_2 != 'no' and op_3 == 'no':
return [op_2]

if op_1 != 'no' and op_2 == 'no' and op_3 == 'no':
return [op_1]

if count(points, op_1) >= count(points, op_2):
if count(points, op_1) >= count(points, op_3):
return [op_1]
else:
return [op_3]
elif count(points, op_2) >= count(points, op_3):
return [op_2]
else:
return [op_3]







def priorities(lane, step, points, bord, cur_pos_x , cur_pos_y):
min_x, max_x = find_lane(cur_pos_x, cur_pos_y)
if lane > max_x or lane < min_x:
return ['no']
if step <= 0:
return ["finish"]

points += (bord[cur_pos_x][cur_pos_y])

R = ['r'] + priorities(lane+1, step-1, points, bord, cur_pos_x +1, cur_pos_y +1)
M = ['m'] + priorities(lane, step - 1, points, bord, cur_pos_x, cur_pos_y +1)
L = ['m'] + priorities(lane -1, step - 1, points, bord, cur_pos_x -1, cur_pos_y +1)

return merge(R, M, L, points)



points =
bord = [[[-10], [+5], [+10]], [[+10], [0], [-10]]]
lane = 1
step = 1
cur_pos_x = 1
cur_pos_y = 0

print(priorities(lane, step, points, bord, cur_pos_x, cur_pos_y))


def pen(cur_pos_x, cur_pos_y, obs, world, min_x, max_x):
if min_x < cur_pos_x < max_x:
right_next_obs = world.get((cur_pos_x + 1, cur_pos_y - 2))
left_next_obs = world.get((cur_pos_x - 1, cur_pos_y - 2))
right_obs = world.get((cur_pos_x + 1, cur_pos_y - 1))
left_obs = world.get((cur_pos_x + 1, cur_pos_y - 1))
if right_next_obs == obstacles.PENGUIN and right_obs not in [obstacles.BIKE, obstacles.TRASH,
obstacles.BARRIER]:
return actions.RIGHT
elif left_next_obs == obstacles.PENGUIN and left_obs not in [obstacles.BIKE, obstacles.TRASH,
obstacles.BARRIER]:
return actions.LEFT
elif right_obs == obstacles.PENGUIN:
return actions.RIGHT, actions.PICKUP
elif left_obs == obstacles.PENGUIN:
return actions.LEFT, actions.PICKUP
else:
return actions.NONE
return actions.NONE

Loading