Projekt_AI-Automatyczny_saper/main.py

42 lines
1014 B
Python
Raw Normal View History

2021-03-13 21:16:35 +01:00
import pygame
2021-03-15 19:58:20 +01:00
from Engine.Game import Game
2021-06-14 22:20:20 +02:00
from Engine.Point import Point
from Engine.Population import Population
2021-03-13 21:16:35 +01:00
WIN = pygame.display.set_mode((800, 800))
FPS = 60
2021-06-14 22:20:20 +02:00
def getPopulation(game):
bombList = []
# bombList.append(Point(0,0))
for x in game.board.bombMap:
bombList.append(x)
return bombList
2021-03-13 21:16:35 +01:00
def main():
run = True
clock = pygame.time.Clock()
2021-03-16 18:53:26 +01:00
game = Game(WIN)
2021-06-14 22:20:20 +02:00
population = Population(game.board, game.dTree)
points = population.geneticAlgorithm(getPopulation(game), popSize=100, eliteSize=20, mutationRate=0.01, generations=500)
2021-03-13 21:16:35 +01:00
while run:
pygame.init()
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
2021-03-16 18:53:26 +01:00
pygame.time.delay(200)
2021-04-13 21:27:51 +02:00
if game.finalState():
break
if len(game.getPath()) == 0:
2021-06-14 22:20:20 +02:00
path = game.getBombPath(points.pop(0))
2021-04-13 21:27:51 +02:00
game.savePath(path)
game.moveToNext()
2021-03-15 19:58:20 +01:00
game.update()
2021-03-13 21:16:35 +01:00
2021-06-14 22:20:20 +02:00
main()