Inteligentny_Traktor_Grupa_16/main.py

83 lines
2.3 KiB
Python
Raw Normal View History

2022-03-09 19:51:09 +01:00
import pygame
from src.utils.xgb_model import Model
from src.world import World
from src.tractor import Tractor
from src.settings import Settings
from src.utils.bfs import BFSSearcher
from src.constants import Constants as C
2022-03-09 19:51:09 +01:00
def main():
pygame.init()
settings = Settings()
model = Model()
world = World(settings, model)
tractor = Tractor("Spalinowy", "Nawóz 1", settings, 0 * settings.tile_size, 0 * settings.tile_size, C.RIGHT)
plants_to_water = [tile for tile in world.tiles if tile.to_water == 1]
2022-04-06 18:04:23 +02:00
clock = pygame.time.Clock() # FPS purpose
screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
pygame.display.set_caption('TRAKTOHOLIK')
2022-05-19 17:36:23 +02:00
start_cords = tractor.curr_position
goals = [plant.position for plant in plants_to_water]
cords_idx = tractor.find_nearest_cords(tractor.curr_position, goals)
end_cords = goals[cords_idx]
start_dir = tractor.curr_direction
path = BFSSearcher().search(start_cords, end_cords, start_dir)
2022-04-20 18:58:43 +02:00
2022-03-09 19:51:09 +01:00
run = True
while run:
2022-04-06 18:04:23 +02:00
clock.tick(settings.fps)
world.draw_tiles(screen)
world.draw_lines(screen)
2022-04-06 18:04:23 +02:00
tractor.draw(screen)
2022-03-09 19:51:09 +01:00
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if path:
action = path.pop(0)
tractor.update(action)
else:
tractor.water_plant(world, end_cords)
if len(goals) > 1:
start_cord = goals.pop(cords_idx)
cords_idx = tractor.find_nearest_cords(tractor.curr_position, goals)
end_cords = goals[cords_idx]
start_dir = tractor.curr_direction
path = BFSSearcher().search(start_cord, end_cords, start_dir)
2022-04-22 13:00:58 +02:00
2022-04-20 18:58:43 +02:00
pygame.time.wait(settings.freeze_time)
2022-03-09 19:51:09 +01:00
pygame.display.update()
pygame.quit()
# if __name__ == '__main__':
#
# # inicjalizacja array z zerami
# rows = 10
# cols = 10
# field = np.zeros((rows, cols), dtype=int)
#
# # tworzenie ścian w array
# for i in range(0, 9):
# field[1, i] = 1
#
# field[2, 8] = 1
# field[3, 8] = 1
# field[3, 7] = 1
# field[3, 6] = 1
#
# print(field)
#
# start = (0, 0)
# goals = [(2, 7)]
# while goals:
# goal = goals.pop(0)
# path = a_star(field, start, goal)
# print(path)
main()