BFS #17

Merged
s481834 merged 20 commits from BFS into master 2024-04-24 17:44:08 +02:00
4 changed files with 29 additions and 5 deletions
Showing only changes of commit 1578dd28f9 - Show all commits

9
App.py
View File

@ -21,7 +21,7 @@ pole.draw_grid() #musi byc tutaj wywołane ponieważ inicjalizuje sloty do slown
ui=Ui.Ui(screen)
#Tractor creation
traktor_slot = pole.get_slot_from_cord((0, 0))
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.plug,clock)
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.opryskiwacz,clock)
def init_demo(): #Demo purpose
@ -37,8 +37,13 @@ def init_demo(): #Demo purpose
ui.render_text_to_console(string_to_print="Przejazd inicjalizujacy- traktor sprawdza poziom nawodnienia")
traktor.initial_move(pole)
traktor.reset_pos(pole)
bfsRoot = Tractor.BFS({"x": 0, "y": 0, "direction": "E", "hydradeIndex": traktor.slot_hydrate_dict})
bfsRoot.reverse()
print(bfsRoot)
# ui.render_text(string_to_print="traktor porusza się ścieżką bfs")
traktor.move_by_root(bfsRoot, pole, traktor.irrigateSlot)
start_flag=False
demo_move()
# demo_move()
old_info=get_info(old_info)
for event in pygame.event.get():
if event.type == pygame.QUIT:

View File

@ -51,4 +51,6 @@ class Slot:
def print_status(self):
return f"wspolrzedne: (X:{self.x_axis} Y:{self.y_axis}) "+self.plant.report_status()
def irrigatePlant(self):
self.plant.stan.nawodnienie = 100

View File

@ -72,7 +72,12 @@ def BFS(istate):
elem = fringe.pop(0)
if goalTest(elem.state["hydradeIndex"]):
return elem #TODO ciąg akcji zbudowany z wykorzystaniem pól parent i action
x = elem
tab = []
while x.parent != None:
tab.append(x.action)
x = x.parent
return tab
explored.append(elem)
@ -202,6 +207,16 @@ class Tractor:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
def move_by_root(self, root, pole, action):
for move in root:
if move == 'forward':
self.move_forward(pole)
if move == 'right':
self.turn_right()
if move == 'left':
self.turn_left()
action()
self.clock.tick(3)
#to tak zrobiłam już na później, może się przyda
def change_osprzet(self, new_osprzet):
@ -217,4 +232,6 @@ class Tractor:
print("- Typ:", akcja.typ)
else:
print("Brak akcji przypisanych do tego sprzętu.")
def irrigateSlot(self):
self.slot.irrigatePlant()

View File

@ -1,6 +1,6 @@
CUBE_SIZE = 64
NUM_X = 20
NUM_Y = 12
NUM_X = 5
NUM_Y = 3
#returns true if tractor can move to specified slot
def isValidMove(x, y):