From 1e881497893df16b3ccf2538423e4e8910cb8eea Mon Sep 17 00:00:00 2001 From: Mateusz Date: Wed, 19 Apr 2023 21:16:40 +0200 Subject: [PATCH] created successor function, adjustet truck class --- garbage_truck.py | 6 ++++-- succ.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 succ.py diff --git a/garbage_truck.py b/garbage_truck.py index 45f611a..82a7112 100644 --- a/garbage_truck.py +++ b/garbage_truck.py @@ -8,10 +8,12 @@ class Engine: self.power = power #HP class GarbageTruck: - def __init__(self, dump_location, fuel_capacity, start_pos): + def __init__(self, dump_location, fuel_capacity, xpos, ypos, orientation): self.dump_location = dump_location self.tank = GarbageTank(15, 18000) self.engine = Engine(400) self.fuel = fuel_capacity - self.pos = start_pos + self.xpos = xpos + self.ypos = ypos + self.orientation = orientation self.houses = [] #lista domów do odwiedzenia \ No newline at end of file diff --git a/succ.py b/succ.py new file mode 100644 index 0000000..600471e --- /dev/null +++ b/succ.py @@ -0,0 +1,28 @@ +def succ(xpos, ypos, orientation): + successors = [] + + if orientation == 'N': + successors.append(['LEFT', xpos, ypos, 'W']) + successors.append(['RIGHT', xpos, ypos, 'E']) + if ypos > 0: + successors.append(['FORWARD', xpos, ypos - 50, 'N']) + + if orientation == 'S': + successors.append(['LEFT', xpos, ypos, 'E']) + successors.append(['RIGHT', xpos, ypos, 'W']) + if ypos < 750: + successors.append(['FORWARD', xpos, ypos + 50, 'S']) + + if orientation == 'W': + successors.append(['LEFT', xpos, ypos, 'S']) + successors.append(['RIGHT', xpos, ypos, 'N']) + if xpos > 0: + successors.append(['FORWARD', xpos - 50, ypos, 'W']) + + if orientation == 'E': + successors.append(['LEFT',xpos, ypos, 'N']) + successors.append(['RIGHT', xpos, ypos, 'S']) + if xpos < 750: + successors.append(['FORWARD', xpos + 50, ypos, 'E']) + + return successors