Zaktualizuj 'main.py'
This commit is contained in:
parent
bd33fa3df5
commit
8f0a1ed075
36
main.py
36
main.py
@ -10,12 +10,15 @@ from pygame.locals import (
|
|||||||
QUIT
|
QUIT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Import other files from project
|
# Import other files from project
|
||||||
import field as F
|
import field as F
|
||||||
import node as N
|
import node as N
|
||||||
import plant as P
|
import plant as P
|
||||||
import src.colors as C
|
import src.colors as C
|
||||||
import src.dimensions as D
|
import src.dimensions as D
|
||||||
|
import AI.GeneticAlgorithm as ga
|
||||||
|
import AI.neural_network as nn
|
||||||
import tractor as T
|
import tractor as T
|
||||||
from src import mapschema as maps
|
from src import mapschema as maps
|
||||||
|
|
||||||
@ -44,6 +47,13 @@ if __name__ == "__main__":
|
|||||||
field[row].append(fieldbit)
|
field[row].append(fieldbit)
|
||||||
|
|
||||||
# genetic_algorithm_setup(field)
|
# 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
|
# Create Tractor object
|
||||||
tractor = T.Tractor(field, [0, 0])
|
tractor = T.Tractor(field, [0, 0])
|
||||||
@ -58,9 +68,11 @@ if __name__ == "__main__":
|
|||||||
for row in range(D.GSIZE):
|
for row in range(D.GSIZE):
|
||||||
plants.append([])
|
plants.append([])
|
||||||
for column in range(D.GSIZE):
|
for column in range(D.GSIZE):
|
||||||
if mapschema[column][row] != 0:
|
if best_plant_pop[column][row] != "":
|
||||||
plantbit = P.Plant(field[row][column], mapschema[column][row])
|
plantbit = P.Plant(field[row][column], best_plant_pop[column][row])
|
||||||
plants[row].append(plantbit)
|
plants[row].append(plantbit)
|
||||||
|
else:
|
||||||
|
plants[row].append(0)
|
||||||
|
|
||||||
# Create list for tractor instructions
|
# Create list for tractor instructions
|
||||||
path = []
|
path = []
|
||||||
@ -77,7 +89,6 @@ if __name__ == "__main__":
|
|||||||
# Main loop
|
# Main loop
|
||||||
while RUNNING:
|
while RUNNING:
|
||||||
|
|
||||||
# Look at every event in the queue
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
# Did the user hit a key?
|
# Did the user hit a key?
|
||||||
if event.type == KEYDOWN:
|
if event.type == KEYDOWN:
|
||||||
@ -105,19 +116,11 @@ if __name__ == "__main__":
|
|||||||
tractor.rotate_right()
|
tractor.rotate_right()
|
||||||
elif path[0] == "hydrate":
|
elif path[0] == "hydrate":
|
||||||
tractor.hydrate(field)
|
tractor.hydrate(field)
|
||||||
|
elif path[0] == "fertilize":
|
||||||
|
tractor.fertilize(field)
|
||||||
|
|
||||||
path.pop(0)
|
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
|
# Set the screen background
|
||||||
screen.fill(C.DBROWN)
|
screen.fill(C.DBROWN)
|
||||||
@ -133,9 +136,10 @@ if __name__ == "__main__":
|
|||||||
# Plants grow with every 10th tick, then they are drawn
|
# Plants grow with every 10th tick, then they are drawn
|
||||||
for row in plants:
|
for row in plants:
|
||||||
for plant in row:
|
for plant in row:
|
||||||
plant.tick()
|
if plant != 0:
|
||||||
plant.grow()
|
plant.tick()
|
||||||
screen.blit(plant.surf, plant.rect)
|
plant.grow()
|
||||||
|
screen.blit(plant.surf, plant.rect)
|
||||||
|
|
||||||
# Field are drying with every 100th tick
|
# Field are drying with every 100th tick
|
||||||
if TICKER == 0:
|
if TICKER == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user