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