Dodanie funkcji do obrotu z powrotem
This commit is contained in:
parent
e91bf45be5
commit
410aacdeca
11
agent.py
11
agent.py
@ -1,7 +1,7 @@
|
|||||||
from warehouse import Coordinates, Tile, Pack
|
from warehouse import Coordinates, Tile, Pack
|
||||||
from queue import PriorityQueue
|
from queue import PriorityQueue
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
import pdb
|
from attributes import TURN_LEFT_DIRECTIONS, TURN_RIGHT_DIRECTIONS
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, coord_x, coord_y):
|
def __init__(self, coord_x, coord_y):
|
||||||
@ -29,6 +29,7 @@ class Agent:
|
|||||||
self.warehouse = assigned_warehouse
|
self.warehouse = assigned_warehouse
|
||||||
self.is_loaded = False
|
self.is_loaded = False
|
||||||
self.transported_package = None
|
self.transported_package = None
|
||||||
|
self.direction = "up"
|
||||||
self.dest = Node(1, 1)
|
self.dest = Node(1, 1)
|
||||||
self.closed = list()
|
self.closed = list()
|
||||||
self.open = PriorityQueue()
|
self.open = PriorityQueue()
|
||||||
@ -65,6 +66,14 @@ class Agent:
|
|||||||
self.open.put((neighbour.g_cost, neighbour))
|
self.open.put((neighbour.g_cost, neighbour))
|
||||||
return False
|
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):
|
def heuristic(self, start: Node, goal: Node):
|
||||||
diff_x = pow(goal.x - start.x, 2)
|
diff_x = pow(goal.x - start.x, 2)
|
||||||
diff_y = pow(goal.y - start.y, 2)
|
diff_y = pow(goal.y - start.y, 2)
|
||||||
|
@ -28,3 +28,17 @@ COLORS = {
|
|||||||
'lightblue': (135, 206, 250),
|
'lightblue': (135, 206, 250),
|
||||||
'orange': (255, 165, 0)
|
'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"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user