Structure change to make it easier for users to clone and use the repository.

This commit is contained in:
danielwilczak101
2021-01-26 21:20:38 -06:00
parent 92cea15a09
commit 2fc75aba07
43 changed files with 7 additions and 30 deletions

40
structure/gene.py Normal file
View File

@ -0,0 +1,40 @@
from copy import deepcopy
class Gene:
def __init__(self, value):
"""Initialize a gene with the input value."""
# Copy another gene
try:
self.value = deepcopy(value.value)
# Otherwise copy the given value
except:
self.value = deepcopy(value)
def __eq__(self, other_gene):
"""Comparing two genes by their value."""
return self.value == Gene(other_gene).value
def __repr__(self):
"""
Allows the user to use
gene_string = repr(gene)
gene_data = eval(gene_string)
gene = ga.make_gene(gene_data)
to get a backend representation of the gene.
"""
return repr(self.value)
def __str__(self):
"""
Allows the user to use
str(gene)
print(gene)
to get a frontend representation of the gene.
"""
return f'[{str(self.value)}]'