genetic_alg #34
@ -10,7 +10,7 @@ def main() -> None:
|
|||||||
print(example_genome.grid)
|
print(example_genome.grid)
|
||||||
islands = get_islands(example_genome.grid, example_genome.knights_red)
|
islands = get_islands(example_genome.grid, example_genome.knights_red)
|
||||||
print(f'Roots {islands} and islands count {len(islands)}')
|
print(f'Roots {islands} and islands count {len(islands)}')
|
||||||
# export_map(example_genome.grid) fixme: FileNotFoundError
|
export_map(example_genome.grid)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -2,12 +2,13 @@ import json
|
|||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
import numpy
|
import numpy
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from os.path import isfile, join
|
from os.path import isfile, join
|
||||||
|
|
||||||
|
MAPS_FOLDER = Path("resources/maps/")
|
||||||
|
|
||||||
|
|
||||||
# Save map to file
|
# Save map to file
|
||||||
@ -16,8 +17,9 @@ def export_map(grid: npt.NDArray):
|
|||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
file_name = "map_" + now.strftime("%Y_%m_%d_%H_%M_%S") + ".json"
|
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)
|
json.dump(json_data, write_file)
|
||||||
print("Saved map to file " + file_name)
|
print("Saved map to file " + file_name)
|
||||||
|
|
||||||
@ -30,9 +32,10 @@ def import_random_map() -> object:
|
|||||||
|
|
||||||
|
|
||||||
# Read map from file
|
# Read map from file
|
||||||
def import_map(file: string) -> object:
|
def import_map(file_name: string) -> object:
|
||||||
with open("resources/maps/" + file, "r") as read_file:
|
file_to_open = MAPS_FOLDER / file_name
|
||||||
print("Reading map from file " + file)
|
with open(file_to_open, "r") as read_file:
|
||||||
|
print("Reading map from file " + file_name)
|
||||||
decoded_json = json.load(read_file)
|
decoded_json = json.load(read_file)
|
||||||
|
|
||||||
decoded_grid = numpy.asarray(decoded_json["map"])
|
decoded_grid = numpy.asarray(decoded_json["map"])
|
||||||
|
0
algorithms/genetic/population.py
Normal file
0
algorithms/genetic/population.py
Normal file
Loading…
Reference in New Issue
Block a user