Traktor/source/main.py
2024-04-14 17:20:27 +02:00

71 lines
2.0 KiB
Python

import pygame
import time
import random
from area.constants import WIDTH, HEIGHT, TILE_SIZE, GREY
from area.field import drawWindow
from area.tractor import Tractor, do_actions
from area.field import tiles, fieldX, fieldY
from area.field import get_tile_coordinates
from ground import Dirt
from plant import Plant
from bfs import graphsearch, Istate, succ
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Intelligent tractor')
def main():
run = True
window = drawWindow(WIN)
pygame.display.update()
#getting coordinates of a certain tile - test:
tile_index=30
tile_x, tile_y = get_tile_coordinates(tile_index)
if tile_x is not None and tile_y is not None:
print(f"Coordinates of tile {tile_index} are: ({tile_x}, {tile_y})")
else: print("Such tile does not exist")
#graphsearch activation:
istate = Istate(170, 100, 2)
goaltest = []
goaltest.append(tile_x)
goaltest.append(tile_y)
moves = (graphsearch(istate, succ, goaltest))
print(moves)
#main loop:
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
#small test of work_on_field method:
time.sleep(1)
tile1 = tiles[0]
p1 = Plant('wheat', 'cereal', random.randint(1,100), random.randint(1,100), random.randint(1,100))
d1 = Dirt(random.randint(1, 100), random.randint(1,100))
d1.pests_and_weeds()
tile1.ground=d1
#movement based on route-planning test:
tractor = Tractor(0*TILE_SIZE, 0*TILE_SIZE, 2)
tractor.rect.x += fieldX
tractor.rect.y += fieldY
tractor.draw_tractor(WIN)
time.sleep(1)
if moves != None:
do_actions(tractor, WIN, moves)
tractor.work_on_field(tile1, d1, p1)
time.sleep(2)
print("\n")
# in loop move tractor:
main()