Dodanie funkcji dla obrotu w lewo i w prawo
This commit is contained in:
parent
716b4f0577
commit
976d285e4b
11
agent.py
11
agent.py
@ -1,5 +1,5 @@
|
|||||||
from warehouse import Coordinates, Tile, Pack
|
from warehouse import Coordinates, Tile, Pack
|
||||||
from attributes import PackStatus
|
from attributes import PackStatus, TURN_LEFT_DIRECTIONS, TURN_RIGHT_DIRECTIONS
|
||||||
|
|
||||||
class Agent:
|
class Agent:
|
||||||
def __init__(self, start_x, start_y, assigned_warehouse, radius=5):
|
def __init__(self, start_x, start_y, assigned_warehouse, radius=5):
|
||||||
@ -27,6 +27,15 @@ class Agent:
|
|||||||
else:
|
else:
|
||||||
self.x = next_coords.x
|
self.x = next_coords.x
|
||||||
self.y = next_coords.y
|
self.y = next_coords.y
|
||||||
|
|
||||||
|
def turn_left(self):
|
||||||
|
new_direction = TURN_LEFT_DIRECTIONS.get(self.direction, self.direction)
|
||||||
|
self.direction = new_direction
|
||||||
|
|
||||||
|
def turn_right(self):
|
||||||
|
new_direction = TURN_RIGHT_DIRECTIONS.get(self.direction, self.direction)
|
||||||
|
self.direction = new_direction
|
||||||
|
|
||||||
def move(self):
|
def move(self):
|
||||||
next_coords = self.get_next_move_coordinates()
|
next_coords = self.get_next_move_coordinates()
|
||||||
can_move = self.check_if_can_move(next_coords)
|
can_move = self.check_if_can_move(next_coords)
|
||||||
|
@ -25,4 +25,19 @@ COLORS = {
|
|||||||
'yellow': (235, 235, 0),
|
'yellow': (235, 235, 0),
|
||||||
'lightgreen': (70, 238, 70),
|
'lightgreen': (70, 238, 70),
|
||||||
'red': (255, 0, 0)
|
'red': (255, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TURN_LEFT_DIRECTIONS = {
|
||||||
|
"left": "down",
|
||||||
|
"down": "right",
|
||||||
|
"right": "up",
|
||||||
|
"up": "left"
|
||||||
|
}
|
||||||
|
|
||||||
|
TURN_RIGHT_DIRECTIONS = {
|
||||||
|
"left": "up",
|
||||||
|
"up": "right",
|
||||||
|
"right": "down",
|
||||||
|
"down": "left"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user