Dodanie funkcji do obrotu z powrotem

This commit is contained in:
andrzej 2020-04-29 00:50:38 +02:00
parent e91bf45be5
commit 410aacdeca
2 changed files with 24 additions and 1 deletions

View File

@ -1,7 +1,7 @@
from warehouse import Coordinates, Tile, Pack
from queue import PriorityQueue
from math import sqrt
import pdb
from attributes import TURN_LEFT_DIRECTIONS, TURN_RIGHT_DIRECTIONS
class Node:
def __init__(self, coord_x, coord_y):
@ -29,6 +29,7 @@ class Agent:
self.warehouse = assigned_warehouse
self.is_loaded = False
self.transported_package = None
self.direction = "up"
self.dest = Node(1, 1)
self.closed = list()
self.open = PriorityQueue()
@ -65,6 +66,14 @@ class Agent:
self.open.put((neighbour.g_cost, neighbour))
return False
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 heuristic(self, start: Node, goal: Node):
diff_x = pow(goal.x - start.x, 2)
diff_y = pow(goal.y - start.y, 2)

View File

@ -28,3 +28,17 @@ COLORS = {
'lightblue': (135, 206, 250),
'orange': (255, 165, 0)
}
TURN_LEFT_DIRECTIONS = {
"left": "down",
"down": "right",
"right": "up",
"up": "left"
}
TURN_RIGHT_DIRECTIONS = {
"left": "up",
"up": "right",
"right": "down",
"down": "left"
}