70 lines
1.8 KiB
Python
70 lines
1.8 KiB
Python
|
#Funkcja konwertujaca wspolrzedne nastepnego pola do odwiedzenia
|
||
|
#na kolejke akcji do wykonania
|
||
|
|
||
|
# tl - turn left, tr - turn right, fwd - forward, op - open
|
||
|
#queue - kolejka akcji do zrobienia, pole klasy Player
|
||
|
#path - kolejka pol do odwiedzenia, pole klasy Player
|
||
|
|
||
|
#pole to element wziety z kolejki path
|
||
|
|
||
|
def actionPlanner(self,pole):
|
||
|
x0 = self.pos[0]
|
||
|
y0 = self.pos[1]
|
||
|
x = pole[0]
|
||
|
y = pole[1]
|
||
|
if (x > x0):
|
||
|
if (self.direction == 1):
|
||
|
self.queue.insert("fwd")
|
||
|
elif (self.direction == 0):
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("fwd")
|
||
|
elif (self.direction == 2):
|
||
|
self.queue.insert("tl")
|
||
|
self.queue.insert("fwd")
|
||
|
else:
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("fwd")
|
||
|
elif (x < x0):
|
||
|
if (self.direction == 3):
|
||
|
self.queue.insert("fwd")
|
||
|
elif (self.direction == 0):
|
||
|
self.queue.insert("tl")
|
||
|
self.queue.insert("fwd")
|
||
|
elif (self.direction == 2):
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("fwd")
|
||
|
else:
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("fwd")
|
||
|
else:
|
||
|
if (y > y0):
|
||
|
if (self.direction == 0):
|
||
|
self.queue.insert("fwd")
|
||
|
elif (self.direction == 1):
|
||
|
self.queue.insert("tl")
|
||
|
self.queue.insert("fwd")
|
||
|
elif (self.direction == 3):
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("fwd")
|
||
|
else:
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("fwd")
|
||
|
else:
|
||
|
if (self.direction == 2):
|
||
|
self.queue.insert("fwd")
|
||
|
elif (self.direction == 3):
|
||
|
self.queue.insert("tl")
|
||
|
self.queue.insert("fwd")
|
||
|
elif (self.direction == 1):
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("fwd")
|
||
|
else:
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("tr")
|
||
|
self.queue.insert("fwd")
|
||
|
if (self.path.empty()):
|
||
|
self.queue.insert("op")
|