traktor jezdzi po calym polu i sadzi jak nalezy

This commit is contained in:
Hubert Westerlich 2024-05-12 21:42:30 +02:00
parent 3b3097d3ec
commit aae7ad82e8
2 changed files with 33 additions and 7 deletions

View File

@ -20,7 +20,7 @@ class Tile(pygame.sprite.Sprite):
vegetables = tractor_kb.query(pl.Expr("warzywo(Nazwa_warzywa)")) vegetables = tractor_kb.query(pl.Expr("warzywo(Nazwa_warzywa)"))
random_vegetable = vegetables[random.randint(0, len(vegetables)-1)]['Nazwa_warzywa'] random_vegetable = vegetables[random.randint(0, len(vegetables)-1)]['Nazwa_warzywa']
if random_vegetable in {'cebula','pietruszka','bób', 'dynia'}: if random_vegetable in {'cebula','pietruszka','bób', 'dynia','ziemniak'}:
random_vegetable = 'marchew' random_vegetable = 'marchew'
self.set_type(random_vegetable) self.set_type(random_vegetable)

View File

@ -1,3 +1,6 @@
import time
from typing import Optional
import pygame import pygame
import os import os
from kb import ile_podlac, multi_sasiedzi from kb import ile_podlac, multi_sasiedzi
@ -136,6 +139,28 @@ class Tractor(pygame.sprite.Sprite):
self.rotate('left') self.rotate('left')
self.rect.y -= TILE_SIZE self.rect.y -= TILE_SIZE
def move_2(self):
x = self.rect.x // TILE_SIZE
y = self.rect.y // TILE_SIZE
if y == 1 and x == 0:
self.move()
elif y == 0 and x == 1:
self.move()
elif y == 15 and x == 1:
self.move()
elif y == 15 and x == 0:
self.rotate('right')
self.move()
elif x == 15:
self.rotate('right')
self.move()
elif x == 1:
self.rotate('left')
self.move()
else:
self.move()
def update(self): def update(self):
# A STAR: # A STAR:
# if self.action_index == len(self.actions): # if self.action_index == len(self.actions):
@ -152,13 +177,13 @@ class Tractor(pygame.sprite.Sprite):
# DECISION TREE: # 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'
self.prev_action = action self.prev_action = action
if self.prev_action is not None and self.prev_action != 'move':
self.move_rotating()
self.prev_action = 'move'
match (action): match (action):
case ('move'): case ('move'):
self.move_rotating() pass
#self.move_rotating()
case ('harvest'): case ('harvest'):
self.get_current_tile().set_type('grass') self.get_current_tile().set_type('grass')
case ('water'): case ('water'):
@ -178,7 +203,7 @@ class Tractor(pygame.sprite.Sprite):
case ('plant(dynia)'): case ('plant(dynia)'):
self.get_current_tile().set_type('fasola') self.get_current_tile().set_type('fasola')
case ('plant(fasola)'): case ('plant(fasola)'):
self.get_current_tile().set_type('fasola') self.get_current_tile().set_type('fasola')
case ('plant(groch)'): case ('plant(groch)'):
self.get_current_tile().set_type('groch') self.get_current_tile().set_type('groch')
case ('plant(jarmuż)'): case ('plant(jarmuż)'):
@ -213,6 +238,7 @@ 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 #self.action_index += 1
print(action) print(action)
return return