AI_PRO/FindPath.py

39 lines
1.6 KiB
Python
Raw Normal View History

2021-04-13 21:39:04 +02:00
from constants import *
def whichStateLookingFor(tractor, TillageUnit):
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
def nearestLookingField(board, tractor, TillageUnit):
x = whichStateLookingFor(tractor, TillageUnit)
for i in range(0, int(HORIZONTAL_TILES_NUMBER)):
for j in range(0, int(VERTICAL_TILES_NUMBER)):
field = board[i][j]
if x == field.state:
end_horizontal_index = field.horizontal_index
end_vertical_index = field.vertical_index
break
else:
print('Wroc do bazy zmienic narzedzie')
end_horizontal_index = 0
end_vertical_index = 0
return(end_horizontal_index, end_vertical_index)
def graphsearch(tractor, board, TillageUnit):
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)