import pygame import warnings warnings.simplefilter(action='ignore', category=FutureWarning) from src.utils.xgb_model import XgbModel 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 from utils.display_info import display_tile_info def main(): warnings.simplefilter(action='ignore', category=FutureWarning) pygame.init() settings = Settings() xgb_model = XgbModel() world = World(settings, xgb_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] clock = pygame.time.Clock() # FPS purpose screen = pygame.display.set_mode((settings.screen_width, settings.screen_height)) pygame.display.set_caption('TRAKTOHOLIK') screen.blit(pygame.image.load('assets/images/display_info/img_frame.jpg'), (700, 0)) 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) run = True while run: clock.tick(settings.fps) world.draw_tiles(screen) world.draw_lines(screen) tractor.draw(screen) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: display_tile_info(world, screen) 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) pygame.time.wait(settings.freeze_time) pygame.display.update() pygame.quit() if __name__ == '__main__': 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)