genetic_alg_angela #31

Merged
s464965 merged 2 commits from genetic_alg_angela into genetic_alg 2022-06-02 00:52:54 +02:00
3 changed files with 9 additions and 6 deletions
Showing only changes of commit f255178162 - Show all commits

View File

@ -10,7 +10,7 @@ def main() -> None:
print(example_genome.grid)
islands = get_islands(example_genome.grid, example_genome.knights_red)
print(f'Roots {islands} and islands count {len(islands)}')
# export_map(example_genome.grid) fixme: FileNotFoundError
export_map(example_genome.grid)
if __name__ == '__main__':

View File

@ -2,12 +2,13 @@ import json
import random
import string
from datetime import datetime
from pathlib import Path
import numpy
import numpy.typing as npt
from os import listdir
from os.path import isfile, join
MAPS_FOLDER = Path("resources/maps/")
# Save map to file
@ -16,8 +17,9 @@ def export_map(grid: npt.NDArray):
now = datetime.now()
file_name = "map_" + now.strftime("%Y_%m_%d_%H_%M_%S") + ".json"
file_to_open = MAPS_FOLDER / file_name
with open("resources/maps/" + file_name, "w") as write_file:
with open(file_to_open, "w") as write_file:
json.dump(json_data, write_file)
print("Saved map to file " + file_name)
@ -30,9 +32,10 @@ def import_random_map() -> object:
# Read map from file
def import_map(file: string) -> object:
with open("resources/maps/" + file, "r") as read_file:
print("Reading map from file " + file)
def import_map(file_name: string) -> object:
file_to_open = MAPS_FOLDER / file_name
with open(file_to_open, "r") as read_file:
print("Reading map from file " + file_name)
decoded_json = json.load(read_file)
decoded_grid = numpy.asarray(decoded_json["map"])

View File