2022-03-09 19:51:09 +01:00
|
|
|
import pygame
|
|
|
|
|
2022-05-29 22:07:47 +02:00
|
|
|
from src.utils.xgb_model import Model
|
2022-03-22 21:34:50 +01:00
|
|
|
from src.world import World
|
|
|
|
from src.tractor import Tractor
|
|
|
|
from src.settings import Settings
|
2022-05-29 22:07:47 +02:00
|
|
|
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()
|
|
|
|
|
2022-05-29 22:07:47 +02:00
|
|
|
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
|
2022-03-22 21:34:50 +01:00
|
|
|
|
2022-05-29 22:07:47 +02:00
|
|
|
screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
|
|
|
|
pygame.display.set_caption('TRAKTOHOLIK')
|
2022-05-19 17:36:23 +02:00
|
|
|
|
2022-05-29 22:07:47 +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)
|
2022-03-31 13:13:43 +02:00
|
|
|
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
|
|
|
|
|
2022-05-18 20:05:47 +02:00
|
|
|
if path:
|
2022-05-29 22:07:47 +02:00
|
|
|
action = path.pop(0)
|
|
|
|
tractor.update(action)
|
2022-05-18 20:05:47 +02:00
|
|
|
else:
|
2022-05-29 22:07:47 +02:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
2022-05-29 22:07:47 +02:00
|
|
|
# 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()
|