From 976d285e4bba7cf481bef605c8218a15964358c3 Mon Sep 17 00:00:00 2001 From: andrzej Date: Thu, 23 Apr 2020 20:55:51 +0200 Subject: [PATCH] Dodanie funkcji dla obrotu w lewo i w prawo --- agent.py | 11 ++++++++++- attributes.py | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/agent.py b/agent.py index 7a45721..2645586 100644 --- a/agent.py +++ b/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) diff --git a/attributes.py b/attributes.py index 3b33a48..a3667b4 100644 --- a/attributes.py +++ b/attributes.py @@ -25,4 +25,19 @@ COLORS = { 'yellow': (235, 235, 0), 'lightgreen': (70, 238, 70), 'red': (255, 0, 0) - } \ No newline at end of file + } + + +TURN_LEFT_DIRECTIONS = { + "left": "down", + "down": "right", + "right": "up", + "up": "left" +} + +TURN_RIGHT_DIRECTIONS = { + "left": "up", + "up": "right", + "right": "down", + "down": "left" +} \ No newline at end of file