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 attributes import PackStatus
|
||||
from attributes import PackStatus, TURN_LEFT_DIRECTIONS, TURN_RIGHT_DIRECTIONS
|
||||
|
||||
class Agent:
|
||||
def __init__(self, start_x, start_y, assigned_warehouse, radius=5):
|
||||
@ -27,6 +27,15 @@ class Agent:
|
||||
else:
|
||||
self.x = next_coords.x
|
||||
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):
|
||||
next_coords = self.get_next_move_coordinates()
|
||||
can_move = self.check_if_can_move(next_coords)
|
||||
|
@ -26,3 +26,18 @@ COLORS = {
|
||||
'lightgreen': (70, 238, 70),
|
||||
'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