feat(utils, ai): set neat config file location in Config

This commit is contained in:
Kristofers Solo 2024-01-05 16:26:19 +02:00
parent daadaeb2c6
commit e6cef45d19
4 changed files with 12 additions and 15 deletions

View File

@ -1,13 +0,0 @@
import neat
from utils import BASE_PATH
def get_config() -> neat.Config:
config_path = BASE_PATH / "config.txt"
return neat.Config(
neat.DefaultGenome,
neat.DefaultReproduction,
neat.DefaultSpeciesSet,
neat.DefaultStagnation,
config_path,
)

View File

@ -5,6 +5,16 @@ import neat
from utils import CONFIG from utils import CONFIG
def get_config() -> neat.Config:
return neat.Config(
neat.DefaultGenome,
neat.DefaultReproduction,
neat.DefaultSpeciesSet,
neat.DefaultStagnation,
CONFIG.ai.config_path,
)
def load_genome() -> neat.DefaultGenome: def load_genome() -> neat.DefaultGenome:
with open(CONFIG.ai.winner_path, "rb") as f: with open(CONFIG.ai.winner_path, "rb") as f:
return pickle.load(f) return pickle.load(f)

View File

@ -5,9 +5,8 @@ import pygame
from game import Main from game import Main
from utils import BASE_PATH, CONFIG from utils import BASE_PATH, CONFIG
from .config import get_config
from .evaluations import eval_genome from .evaluations import eval_genome
from .io import save_genome from .io import get_config, save_genome
from .log import log from .log import log
from .visualize import plot_progress, plot_species, plot_stats from .visualize import plot_progress, plot_species, plot_stats

View File

@ -65,6 +65,7 @@ class AI:
winner_path: Path = BASE_PATH / "winner" winner_path: Path = BASE_PATH / "winner"
plot_path: Path = BASE_PATH / "plots" plot_path: Path = BASE_PATH / "plots"
checkpoint_path: Path = BASE_PATH / "checkpoints" checkpoint_path: Path = BASE_PATH / "checkpoints"
config_path: Path = BASE_PATH / "config"
@define @define