From eb5556e5149a450887e23f708a9eab22cca00902 Mon Sep 17 00:00:00 2001 From: tafit0902 Date: Sat, 13 Apr 2024 23:49:04 +0200 Subject: [PATCH 1/4] poprawki --- Pole.py | 4 ++-- Tractor.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Pole.py b/Pole.py index f2c6f4d..983dbf9 100644 --- a/Pole.py +++ b/Pole.py @@ -55,8 +55,8 @@ class Pole: def check_collision(self,mouse_x,mouse_y): mouse_x=math.floor(mouse_x/dCon.CUBE_SIZE) mouse_y=math.floor(mouse_y/dCon.CUBE_SIZE) - if(mouse_x<20): - if(mouse_y<12): + if(mouse_x Date: Sat, 13 Apr 2024 23:55:58 +0200 Subject: [PATCH 2/4] traktor porusza sie po scieszce bfs i nawadnia na sztywno pole --- App.py | 9 +++++++-- Slot.py | 2 ++ Tractor.py | 19 ++++++++++++++++++- displayControler.py | 4 ++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/App.py b/App.py index d3c0a73..4a92366 100644 --- a/App.py +++ b/App.py @@ -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: diff --git a/Slot.py b/Slot.py index b50f872..262ee12 100644 --- a/Slot.py +++ b/Slot.py @@ -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 \ No newline at end of file diff --git a/Tractor.py b/Tractor.py index 74afc34..0e8aa5a 100644 --- a/Tractor.py +++ b/Tractor.py @@ -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() diff --git a/displayControler.py b/displayControler.py index f09da3f..cad2f16 100644 --- a/displayControler.py +++ b/displayControler.py @@ -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): -- 2.20.1 From fbe6a7e386e36f8926d5c473e06c63c848ad3886 Mon Sep 17 00:00:00 2001 From: tafit0902 Date: Sun, 14 Apr 2024 00:13:27 +0200 Subject: [PATCH 3/4] poprawa obrotu traktora --- App.py | 2 +- Tractor.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/App.py b/App.py index 4a92366..9ae7626 100644 --- a/App.py +++ b/App.py @@ -41,7 +41,7 @@ def init_demo(): #Demo purpose bfsRoot.reverse() print(bfsRoot) # ui.render_text(string_to_print="traktor porusza się ścieżką bfs") - traktor.move_by_root(bfsRoot, pole, traktor.irrigateSlot) + traktor.move_by_root(bfsRoot, pole, [traktor.irrigateSlot]) start_flag=False # demo_move() old_info=get_info(old_info) diff --git a/Tractor.py b/Tractor.py index 0e8aa5a..8cbee1f 100644 --- a/Tractor.py +++ b/Tractor.py @@ -207,15 +207,18 @@ class Tractor: for event in pygame.event.get(): if event.type == pygame.QUIT: quit() - def move_by_root(self, root, pole, action): + def move_by_root(self, root, pole, actions = None): for move in root: + self.slot.redraw_image() if move == 'forward': self.move_forward(pole) if move == 'right': self.turn_right() if move == 'left': self.turn_left() - action() + for a in actions: + a() + self.clock.tick(3) #to tak zrobiłam już na później, może się przyda -- 2.20.1 From 2c03c4857cb2178b5b12dd609e3afa5d1ccd3b3d Mon Sep 17 00:00:00 2001 From: tafit0902 Date: Sun, 14 Apr 2024 00:41:18 +0200 Subject: [PATCH 4/4] poprawki --- App.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/App.py b/App.py index 9ae7626..be9f2d5 100644 --- a/App.py +++ b/App.py @@ -39,8 +39,7 @@ def init_demo(): #Demo purpose 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") + # ui.render_text_to_console(string_to_print="traktor porusza się ścieżką bfs") traktor.move_by_root(bfsRoot, pole, [traktor.irrigateSlot]) start_flag=False # demo_move() -- 2.20.1