field cost

This commit is contained in:
secret_dude 2021-04-27 19:36:48 +02:00
parent 1bdef8cc56
commit 5e4af5773b
4 changed files with 35 additions and 12 deletions

View File

@ -11,8 +11,17 @@ def generate():
for i in range(0, int(HORIZONTAL_TILES_NUMBER)): for i in range(0, int(HORIZONTAL_TILES_NUMBER)):
board.append([]) board.append([])
for j in range(0, int(VERTICAL_TILES_NUMBER)): for j in range(0, int(VERTICAL_TILES_NUMBER)):
board[i].append(Field(int(i * TILE_SIZE), int(j * TILE_SIZE), random.choice(states))) current_state = random.choice(states)
current_cost = getCost(current_state)
board[i].append(Field(int(i * TILE_SIZE), int(j * TILE_SIZE), current_state, current_cost))
board[0][0] = Field(int(0 * TILE_SIZE), int(0 * TILE_SIZE), "TOOLS_FIELD") board[0][0] = Field(int(0 * TILE_SIZE), int(0 * TILE_SIZE), "TOOLS_FIELD", cost=0)
board[1][0] = Field(int(1 * TILE_SIZE), int(0 * TILE_SIZE), "FUEL_FIELD") board[1][0] = Field(int(1 * TILE_SIZE), int(0 * TILE_SIZE), "FUEL_FIELD", cost=0)
return board return board
def getCost(state):
if state == 'toPlow': return 1
if state == 'toSeed': return 2
if state == 'toFertilize': return 3
if state == 'toWater': return 4
if state == 'toCut': return 5

View File

@ -1,13 +1,18 @@
class Field: class Field:
def __init__(self, horizontal_index, vertical_index, state): def __init__(self, horizontal_index, vertical_index, state, cost):
self.__horizontal_index = horizontal_index self.__horizontal_index = horizontal_index
self.__vertical_index = vertical_index self.__vertical_index = vertical_index
self.__state = state self.__state = state
self.__cost = cost
@property @property
def state(self): def state(self):
return self.__state return self.__state
@property
def cost(self):
return self.__cost
@property @property
def horizontal_index(self): def horizontal_index(self):
return self.__horizontal_index return self.__horizontal_index
@ -21,3 +26,9 @@ class Field:
if state == "toPlow" or state == "toWater" or state == "toSeed" or \ if state == "toPlow" or state == "toWater" or state == "toSeed" or \
state == "toFertilize" or state == "toCut" or state == "TOOLS_FIELD" or state == "FUEL_FIELD": state == "toFertilize" or state == "toCut" or state == "TOOLS_FIELD" or state == "FUEL_FIELD":
self.__state = state self.__state = state
@cost.setter
def cost(self, cost):
if cost == 1 or cost == 2 or cost == 3 or \
cost == 4 or cost == 5 or cost == 0:
self.__cost = cost

View File

@ -30,11 +30,16 @@ def whichStateLookingFor(tractor, TillageUnit):
def nearestLookingField(board, tractor, TillageUnit): def nearestLookingField(board, tractor, TillageUnit):
horizontal_tiles_number = int(HORIZONTAL_TILES_NUMBER)
vertical_tiles_number = int(VERTICAL_TILES_NUMBER)
print(horizontal_tiles_number, vertical_tiles_number)
a = input()
end_horizontal_index = 0 end_horizontal_index = 0
end_vertical_index = 0 end_vertical_index = 0
searching_field = whichStateLookingFor(tractor, TillageUnit) searching_field = whichStateLookingFor(tractor, TillageUnit)
for i in range(0, int(HORIZONTAL_TILES_NUMBER)): for i in range(horizontal_tiles_number):
for j in range(0, int(VERTICAL_TILES_NUMBER)): for j in range(vertical_tiles_number):
field = board[i][j] field = board[i][j]
if searching_field == field.state: if searching_field == field.state:
end_horizontal_index = field.horizontal_index end_horizontal_index = field.horizontal_index
@ -62,8 +67,8 @@ def graphsearch(tractor, board, TillageUnit, fringe: Queue, explored):
if goaltest(elem, end_state): if goaltest(elem, end_state):
break break
# TODO #TODO
# return droga ktora musi pokonac traktor #return droga ktora musi pokonac traktor
else: else:
explored.append(elem) explored.append(elem)
elem = succ(start_state, end_state, tractor) elem = succ(start_state, end_state, tractor)
@ -71,10 +76,8 @@ def graphsearch(tractor, board, TillageUnit, fringe: Queue, explored):
def goaltest(elem, end_state): def goaltest(elem, end_state):
print('element: ',elem,' stan koncowy; ', end_state) print('element:', elem, 'state:', end_state)
if elem == end_state: if elem == end_state:
print("heeee")
return True return True
else: else:
return False return False

View File

@ -59,7 +59,7 @@ while working:
clock.tick(FPS) clock.tick(FPS)
graphsearch(tractor, board, TillageUnit, Queue(), list()) #graphsearch(tractor, board, TillageUnit, Queue(), list())
pygame.quit() pygame.quit()
quit() quit()