From 8f0a1ed075e660d2f490edf6df6fad1abcebc383 Mon Sep 17 00:00:00 2001 From: Cezary Adamczak Date: Mon, 21 Jun 2021 14:02:50 +0200 Subject: [PATCH] Zaktualizuj 'main.py' --- main.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 7203e66..110d04f 100644 --- a/main.py +++ b/main.py @@ -10,12 +10,15 @@ from pygame.locals import ( QUIT ) + # Import other files from project import field as F import node as N import plant as P import src.colors as C import src.dimensions as D +import AI.GeneticAlgorithm as ga +import AI.neural_network as nn import tractor as T from src import mapschema as maps @@ -44,6 +47,13 @@ if __name__ == "__main__": field[row].append(fieldbit) # genetic_algorithm_setup(field) + num_of_plants = 0 + plant_pops = [] + best_plant_pop = [] + + goal_gen = 10 + best_plant_pop, plant_pops, num_of_plants, fitness = ga.genetic_algorithm_setup(field, plant_pops, goal_gen) + # Create Tractor object tractor = T.Tractor(field, [0, 0]) @@ -58,9 +68,11 @@ if __name__ == "__main__": for row in range(D.GSIZE): plants.append([]) for column in range(D.GSIZE): - if mapschema[column][row] != 0: - plantbit = P.Plant(field[row][column], mapschema[column][row]) + if best_plant_pop[column][row] != "": + plantbit = P.Plant(field[row][column], best_plant_pop[column][row]) plants[row].append(plantbit) + else: + plants[row].append(0) # Create list for tractor instructions path = [] @@ -77,7 +89,6 @@ if __name__ == "__main__": # Main loop while RUNNING: - # Look at every event in the queue for event in pygame.event.get(): # Did the user hit a key? if event.type == KEYDOWN: @@ -105,19 +116,11 @@ if __name__ == "__main__": tractor.rotate_right() elif path[0] == "hydrate": tractor.hydrate(field) + elif path[0] == "fertilize": + tractor.fertilize(field) path.pop(0) - # Get all keys pressed at a time CURRENTLY UNUSED - pressed_keys = pygame.key.get_pressed() - - # control tractor with pressed keys CURRENTLY UNUSED - if pressed_keys[K_UP]: - tractor.move() - elif pressed_keys[K_LEFT]: - tractor.rotate_left() - elif pressed_keys[K_RIGHT]: - tractor.rotate_right() # Set the screen background screen.fill(C.DBROWN) @@ -133,9 +136,10 @@ if __name__ == "__main__": # Plants grow with every 10th tick, then they are drawn for row in plants: for plant in row: - plant.tick() - plant.grow() - screen.blit(plant.surf, plant.rect) + if plant != 0: + plant.tick() + plant.grow() + screen.blit(plant.surf, plant.rect) # Field are drying with every 100th tick if TICKER == 0: