mirror of
https://github.com/kristoferssolo/2048.git
synced 2025-10-21 15:20:35 +00:00
refactor(AI): update change condition
This commit is contained in:
parent
73548ed8f4
commit
62c56b1911
BIN
best_genome
BIN
best_genome
Binary file not shown.
BIN
best_genome.pkl
BIN
best_genome.pkl
Binary file not shown.
@ -1,16 +1,18 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
import neat
|
import neat
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from py2048 import Menu
|
from py2048 import Menu
|
||||||
|
|
||||||
|
|
||||||
def eval_genomes(genomes, config: neat.Config):
|
def eval_genomes(genomes, config: neat.Config):
|
||||||
for genome_id, genome in genomes:
|
|
||||||
genome.fitness = 0
|
|
||||||
app = Menu()
|
app = Menu()
|
||||||
net = neat.nn.FeedForwardNetwork.create(genome, config)
|
|
||||||
|
|
||||||
app.play()
|
app.play()
|
||||||
app._game_active = False
|
app._game_active = False
|
||||||
|
for genome_id, genome in genomes:
|
||||||
|
genome.fitness = 0
|
||||||
|
net = neat.nn.FeedForwardNetwork.create(genome, config)
|
||||||
|
start_time = time.perf_counter()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
output = net.activate(
|
output = net.activate(
|
||||||
@ -35,9 +37,14 @@ def eval_genomes(genomes, config: neat.Config):
|
|||||||
app.game.draw(app._surface)
|
app.game.draw(app._surface)
|
||||||
max_val = app.game.board.max_val()
|
max_val = app.game.board.max_val()
|
||||||
|
|
||||||
if app.game.board._is_full() or max_val >= 2048:
|
time_passed = time.perf_counter() - start_time
|
||||||
|
if (
|
||||||
|
app.game.board.is_game_over()
|
||||||
|
or (app.game.board._is_full() and time_passed >= 0.1)
|
||||||
|
or max_val >= 2048
|
||||||
|
):
|
||||||
calculate_fitness(genome, max_val)
|
calculate_fitness(genome, max_val)
|
||||||
logger.info(f"{max_val=}")
|
logger.info(f"{max_val=}\tscore={app.game.board.score}")
|
||||||
app.game.restart()
|
app.game.restart()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user