fix: Slightly changed tractor.py - also checking if branch works

This commit is contained in:
Adam Mikolajczak 2024-06-09 10:39:48 +02:00
parent 4595a5fe83
commit b0ac67a105

View File

@ -32,11 +32,11 @@ class Tractor(pygame.sprite.Sprite):
self.water = 50 self.water = 50
# A-STAR #A-STAR
# came_from, total_cost = self.a_star() came_from, total_cost = self.a_star()
# path = self.reconstruct_path(came_from) path = self.reconstruct_path(came_from)
# self.actions = self.recreate_actions(path) self.actions = self.recreate_actions(path)
# self.action_index = 0 self.action_index = 0
# DECISION TREE: # DECISION TREE:
self.label_encoders = {} self.label_encoders = {}
@ -163,21 +163,7 @@ class Tractor(pygame.sprite.Sprite):
else: else:
self.move() self.move()
def update(self): def decision_tree(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:
action = self.make_decision() action = self.make_decision()
if (self.get_current_tile().type != 'grass' or self.get_current_tile().type == 'water'): action = 'move' if (self.get_current_tile().type != 'grass' or self.get_current_tile().type == 'water'): action = 'move'
self.prev_action = action self.prev_action = action
@ -241,8 +227,22 @@ class Tractor(pygame.sprite.Sprite):
self.get_current_tile().set_type('szpinak') self.get_current_tile().set_type('szpinak')
case ('plant(ziemniak)'): case ('plant(ziemniak)'):
self.get_current_tile().set_type('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": if self.get_current_tile().type == "grass":
print("Co jest faktycznie: trawa") print("Co jest faktycznie: trawa")
@ -255,6 +255,7 @@ class Tractor(pygame.sprite.Sprite):
return return
def log_info(self): def log_info(self):
# print on what tile type the tractor is on # print on what tile type the tractor is on
x = self.rect.x // TILE_SIZE x = self.rect.x // TILE_SIZE