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)"))
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'
self.set_type(random_vegetable)

View File

@ -1,3 +1,6 @@
import time
from typing import Optional
import pygame
import os
from kb import ile_podlac, multi_sasiedzi
@ -136,6 +139,28 @@ class Tractor(pygame.sprite.Sprite):
self.rotate('left')
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):
# A STAR:
# if self.action_index == len(self.actions):
@ -152,13 +177,13 @@ class Tractor(pygame.sprite.Sprite):
# DECISION TREE:
action = self.make_decision()
if (self.get_current_tile().type != 'grass' or self.get_current_tile().type == 'water'): action = 'move'
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):
case ('move'):
self.move_rotating()
pass
#self.move_rotating()
case ('harvest'):
self.get_current_tile().set_type('grass')
case ('water'):
@ -166,7 +191,7 @@ class Tractor(pygame.sprite.Sprite):
case ('plant(bób)'):
self.get_current_tile().set_type('marchew')
case ('plant(brokuł)'):
self.get_current_tile().set_type('brokuł')
self.get_current_tile().set_type('brokuł')
case ('plant(brukselka)'):
self.get_current_tile().set_type('brukselka')
case ('plant(burak)'):
@ -178,7 +203,7 @@ class Tractor(pygame.sprite.Sprite):
case ('plant(dynia)'):
self.get_current_tile().set_type('fasola')
case ('plant(fasola)'):
self.get_current_tile().set_type('fasola')
self.get_current_tile().set_type('fasola')
case ('plant(groch)'):
self.get_current_tile().set_type('groch')
case ('plant(jarmuż)'):
@ -213,6 +238,7 @@ 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
print(action)
return