2021-04-13 21:39:04 +02:00
|
|
|
from constants import *
|
2021-04-14 00:05:16 +02:00
|
|
|
from queue import Queue
|
|
|
|
|
|
|
|
|
|
|
|
class Node:
|
|
|
|
def __init__(self, parent: (int, int), index: (int, int)):
|
|
|
|
self.__index = index
|
|
|
|
self.__parent = parent
|
|
|
|
|
|
|
|
def get_index(self):
|
|
|
|
return self.__index
|
|
|
|
|
|
|
|
def get_parent(self):
|
|
|
|
return self.__parent
|
|
|
|
|
2021-04-13 21:39:04 +02:00
|
|
|
|
|
|
|
def whichStateLookingFor(tractor, TillageUnit):
|
2021-04-13 21:50:08 +02:00
|
|
|
searching_field = "toPlow"
|
2021-04-13 21:39:04 +02:00
|
|
|
if tractor.header and tractor.hitch == "Crop Trailer":
|
|
|
|
searching_field = "toCut"
|
|
|
|
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Nothing":
|
|
|
|
searching_field = "toPlow"
|
|
|
|
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Water":
|
|
|
|
searching_field = "toWater"
|
|
|
|
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Seeds":
|
|
|
|
searching_field = "toSeed"
|
|
|
|
elif isinstance(tractor.hitch, TillageUnit) and tractor.hitch.load == "Fertilizer":
|
|
|
|
searching_field = "toFertilize"
|
|
|
|
return searching_field
|
|
|
|
|
2021-04-14 14:34:57 +02:00
|
|
|
|
2021-04-13 21:39:04 +02:00
|
|
|
def nearestLookingField(board, tractor, TillageUnit):
|
2021-04-27 19:36:48 +02:00
|
|
|
horizontal_tiles_number = int(HORIZONTAL_TILES_NUMBER)
|
|
|
|
vertical_tiles_number = int(VERTICAL_TILES_NUMBER)
|
|
|
|
|
|
|
|
print(horizontal_tiles_number, vertical_tiles_number)
|
|
|
|
a = input()
|
2021-04-13 21:50:08 +02:00
|
|
|
end_horizontal_index = 0
|
|
|
|
end_vertical_index = 0
|
|
|
|
searching_field = whichStateLookingFor(tractor, TillageUnit)
|
2021-04-27 19:36:48 +02:00
|
|
|
for i in range(horizontal_tiles_number):
|
|
|
|
for j in range(vertical_tiles_number):
|
2021-04-13 21:39:04 +02:00
|
|
|
field = board[i][j]
|
2021-04-13 21:50:08 +02:00
|
|
|
if searching_field == field.state:
|
2021-04-13 21:39:04 +02:00
|
|
|
end_horizontal_index = field.horizontal_index
|
|
|
|
end_vertical_index = field.vertical_index
|
|
|
|
break
|
2021-04-14 14:34:57 +02:00
|
|
|
|
2021-04-13 21:50:08 +02:00
|
|
|
return end_horizontal_index, end_vertical_index
|
2021-04-13 21:39:04 +02:00
|
|
|
|
2021-04-14 14:34:57 +02:00
|
|
|
|
2021-04-14 00:05:16 +02:00
|
|
|
def graphsearch(tractor, board, TillageUnit, fringe: Queue, explored):
|
2021-04-13 21:39:04 +02:00
|
|
|
start_horizontal_index = tractor.horizontal_index
|
|
|
|
start_vertical_index = tractor.vertical_index
|
|
|
|
start_state = (start_horizontal_index, start_vertical_index)
|
|
|
|
end_state = nearestLookingField(board, tractor, TillageUnit)
|
|
|
|
print(start_state)
|
|
|
|
print(end_state)
|
|
|
|
|
2021-04-14 00:05:16 +02:00
|
|
|
fringe.put(start_state)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
if fringe.empty():
|
|
|
|
return False
|
|
|
|
|
|
|
|
elem = fringe.get()
|
|
|
|
|
|
|
|
if goaltest(elem, end_state):
|
2021-04-14 01:42:42 +02:00
|
|
|
break
|
2021-04-27 19:36:48 +02:00
|
|
|
#TODO
|
|
|
|
#return droga ktora musi pokonac traktor
|
2021-04-14 01:42:42 +02:00
|
|
|
else:
|
|
|
|
explored.append(elem)
|
|
|
|
elem = succ(start_state, end_state, tractor)
|
|
|
|
fringe.put(elem)
|
2021-04-14 00:05:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def goaltest(elem, end_state):
|
2021-04-27 19:36:48 +02:00
|
|
|
print('element:', elem, 'state:', end_state)
|
2021-04-14 00:05:16 +02:00
|
|
|
if elem == end_state:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2021-04-14 14:34:57 +02:00
|
|
|
|
2021-04-14 01:42:42 +02:00
|
|
|
def succ(start_state, end_state, tractor):
|
2021-04-14 14:34:57 +02:00
|
|
|
print(tractor.horizontal_index, ' ', tractor.vertical_index)
|
|
|
|
a = input()
|
2021-04-14 01:42:42 +02:00
|
|
|
if start_state[1] < end_state[1]:
|
|
|
|
if tractor.direction == "RIGHT":
|
|
|
|
tractor.drive()
|
2021-04-14 14:34:57 +02:00
|
|
|
print("przesunalem sie w prawo")
|
2021-04-14 01:42:42 +02:00
|
|
|
else:
|
|
|
|
tractor.direction = "RIGHT"
|
2021-04-14 14:34:57 +02:00
|
|
|
|
2021-04-14 01:42:42 +02:00
|
|
|
elif start_state[1] > end_state[1]:
|
|
|
|
if tractor.direction == "LEFT":
|
|
|
|
tractor.drive()
|
2021-04-14 14:34:57 +02:00
|
|
|
print("przesunalem sie w lewo")
|
2021-04-14 01:42:42 +02:00
|
|
|
else:
|
|
|
|
tractor.direction = "LEFT"
|
2021-04-14 14:34:57 +02:00
|
|
|
|
|
|
|
elif start_state[0] < end_state[0]:
|
|
|
|
if tractor.direction == "DOWN":
|
|
|
|
tractor.drive()
|
2021-04-14 01:42:42 +02:00
|
|
|
print("przesunalem sie w dol")
|
2021-04-14 14:34:57 +02:00
|
|
|
else:
|
|
|
|
tractor.direction = "DOWN"
|
|
|
|
elif start_state[0] > end_state[0]:
|
|
|
|
if tractor.direction == "UP":
|
|
|
|
tractor.drive()
|
2021-04-14 01:42:42 +02:00
|
|
|
print("przesunalem sie w gore")
|
|
|
|
else:
|
2021-04-14 14:34:57 +02:00
|
|
|
tractor.direction = "UP"
|
|
|
|
else:
|
|
|
|
return tractor.horizontal_index, tractor.horizontal_index
|