From b0ac67a1055a12eed0e3999d3441de05f83484a8 Mon Sep 17 00:00:00 2001 From: Adam Mikolajczak Date: Sun, 9 Jun 2024 10:39:48 +0200 Subject: [PATCH] fix: Slightly changed tractor.py - also checking if branch works --- src/tractor.py | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/tractor.py b/src/tractor.py index b070e0f0..fac7041e 100644 --- a/src/tractor.py +++ b/src/tractor.py @@ -32,11 +32,11 @@ class Tractor(pygame.sprite.Sprite): self.water = 50 - # A-STAR - # came_from, total_cost = self.a_star() - # path = self.reconstruct_path(came_from) - # self.actions = self.recreate_actions(path) - # self.action_index = 0 + #A-STAR + came_from, total_cost = self.a_star() + path = self.reconstruct_path(came_from) + self.actions = self.recreate_actions(path) + self.action_index = 0 # DECISION TREE: self.label_encoders = {} @@ -162,22 +162,8 @@ class Tractor(pygame.sprite.Sprite): self.move() else: self.move() - - def update(self): - # A STAR: - # if self.action_index == len(self.actions): - # return - # action = self.actions[self.action_index] - - # match (action): - # case ('move'): - # self.move() - # case ('left'): - # self.rotate('left') - # case ('right'): - # self.rotate('right') - - # DECISION TREE: + + def decision_tree(self): action = self.make_decision() if (self.get_current_tile().type != 'grass' or self.get_current_tile().type == 'water'): action = 'move' self.prev_action = action @@ -241,8 +227,22 @@ class Tractor(pygame.sprite.Sprite): self.get_current_tile().set_type('szpinak') case ('plant(ziemniak)'): self.get_current_tile().set_type('ziemniak') - self.move_2() - #self.action_index += 1 + + def update(self): + # A STAR: + if self.action_index == len(self.actions): + return + action = self.actions[self.action_index] + + match (action): + case ('move'): + self.move() + case ('left'): + self.rotate('left') + case ('right'): + self.rotate('right') + + self.action_index += 1 if self.get_current_tile().type == "grass": print("Co jest faktycznie: trawa") @@ -255,6 +255,7 @@ class Tractor(pygame.sprite.Sprite): return + def log_info(self): # print on what tile type the tractor is on x = self.rect.x // TILE_SIZE