Zaktualizuj 'main.py'
This commit is contained in:
parent
bd33fa3df5
commit
8f0a1ed075
30
main.py
30
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,6 +136,7 @@ if __name__ == "__main__":
|
||||
# Plants grow with every 10th tick, then they are drawn
|
||||
for row in plants:
|
||||
for plant in row:
|
||||
if plant != 0:
|
||||
plant.tick()
|
||||
plant.grow()
|
||||
screen.blit(plant.surf, plant.rect)
|
||||
|
Loading…
Reference in New Issue
Block a user