feat: After arriving at selected by user tile, Tractor makes decision by using decision tree.

The decision is printed in terminal.
This commit is contained in:
Adam Mikolajczak 2024-06-09 11:26:14 +02:00
parent a6f51420e1
commit 30878adedd

View File

@ -97,13 +97,11 @@ class Tractor(pygame.sprite.Sprite):
def draw(self, surface): def draw(self, surface):
surface.blit(self.image, self.rect) surface.blit(self.image, self.rect)
def get_coordinates(self): def get_coordinates(self):
x = self.rect.x // TILE_SIZE x = self.rect.x // TILE_SIZE
y = self.rect.y // TILE_SIZE y = self.rect.y // TILE_SIZE
return (x,y) return (x,y)
def move(self): def move(self):
if self.direction == "north" and self.rect.y > 0: if self.direction == "north" and self.rect.y > 0:
self.rect.y -= TILE_SIZE self.rect.y -= TILE_SIZE
@ -168,12 +166,13 @@ class Tractor(pygame.sprite.Sprite):
def decision_tree(self): def decision_tree(self):
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 = 'nothing'
self.prev_action = action self.prev_action = action
print("Decyzja podjęta przez drzewo decyzyjne: ", action)
match (action): match (action):
case ('move'): case ('nothing'):
pass pass
#self.move_rotating() #self.move_rotating()
case ('harvest'): case ('harvest'):
@ -255,6 +254,9 @@ class Tractor(pygame.sprite.Sprite):
print("Rozpoznano: ", self.get_current_tile().prediction) print("Rozpoznano: ", self.get_current_tile().prediction)
print("Co jest faktycznie: ", self.get_current_tile().type) print("Co jest faktycznie: ", self.get_current_tile().type)
print("\n") print("\n")
if self.get_coordinates() == self.final:
self.decision_tree()
return return