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 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] clock = pygame.time.Clock() # FPS purpose screen = pygame.display.set_mode((settings.screen_width, settings.screen_height)) pygame.display.set_caption('TRAKTOHOLIK') 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 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__': # # # 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()