Hello!
I’m a bit of a beginner at python, but want to learn how to program a breeding system (similar to FR’s system, where the children’s traits are based on the parents and an image of each child is generated). However I can’t find any tutorials on this. I’ve read a lot about genetical algorithms but I can’t figure out how to customise it to fit my needs (where the fitness is through interactive selection, since the user picks the parents).
Does anyone know of any python tutorials for this? Or would like to maybe help me in DMs, and I’ll elaborate what I don’t understand?
Any tips are welcome! <3
Hello!
I’m a bit of a beginner at python, but want to learn how to program a breeding system (similar to FR’s system, where the children’s traits are based on the parents and an image of each child is generated). However I can’t find any tutorials on this. I’ve read a lot about genetical algorithms but I can’t figure out how to customise it to fit my needs (where the fitness is through interactive selection, since the user picks the parents).
Does anyone know of any python tutorials for this? Or would like to maybe help me in DMs, and I’ll elaborate what I don’t understand?
Any tips are welcome! <3
Not much of a coder myself but I've done some research into it, maybe these could help?
https://realpython.com/simpy-simulating-with-python/
This site has different example walk-through subsections on the left side:
http://www.python-exemplary.com/index_en.php?inhalt_links=navigation_en.inc.php&inhalt_mitte=raspi/en/gsm.inc.php
This site has various tutorials:
https://www.tutorialgateway.org/python-programming-examples/
If you need anymore help, feel free to DM me.
@
notdura genetical algorithms are aiming to solve a problem (usually optimization). what fr does is a bit more mundane- given two parents, pick the breed + genes from the parent genes with weighted probability, pick the colors from the color wheel based on the parents' colors, pick the eye type from an existing pool, and draw the element from the user's nest, in a nutshell. the image is then generated based on these attributes.
if you fancy building the first bit from scratch, doable in vanilla python, you'll want to get familiar with data structures *especially lists, and look into the built-in
random module (import random) for the rng aspect. you'll also find
file i/o useful to carry over data between 'sessions' without hardcoding.
sorry for making you read documentation i could write sample code but i cant guarantee it compiles
you might want to check out classes but i don't think that's as critical to making a functioning program with this complexity :')
as for generating images, you'll need to look into the modules yourself. if you have pip you can install them as needed.
(as an example, stacking images can be done in pil/pillow >
https://stackoverflow.com/questions/5324647/how-to-merge-a-transparent-png-image-with-another-image-using-pil )
good luck!
@
notdura genetical algorithms are aiming to solve a problem (usually optimization). what fr does is a bit more mundane- given two parents, pick the breed + genes from the parent genes with weighted probability, pick the colors from the color wheel based on the parents' colors, pick the eye type from an existing pool, and draw the element from the user's nest, in a nutshell. the image is then generated based on these attributes.
if you fancy building the first bit from scratch, doable in vanilla python, you'll want to get familiar with data structures *especially lists, and look into the built-in
random module (import random) for the rng aspect. you'll also find
file i/o useful to carry over data between 'sessions' without hardcoding.
sorry for making you read documentation i could write sample code but i cant guarantee it compiles
you might want to check out classes but i don't think that's as critical to making a functioning program with this complexity :')
as for generating images, you'll need to look into the modules yourself. if you have pip you can install them as needed.
(as an example, stacking images can be done in pil/pillow >
https://stackoverflow.com/questions/5324647/how-to-merge-a-transparent-png-image-with-another-image-using-pil )
good luck!
@
XsvL8d thank you so much!!!
(And sorry about the late reply, I completely forgot to reply!)
Your answer pretty much confirmed that I've mostly been looking at the wrong things, making the breeding system based on genetical algorithms seems way too complicated :' )) The links you sent will help a lot! Especially the randrange, that one's gonna be perfect for when I start working for real on the breeding system.
Right now I'm currently recoding some of my script, I originally made a pet generator script with pillow to learn. It produced what I wanted to; a pet with the features the user picked, but it wasn't possible to base the breeding system on it since it didn't contain any functions. So now I'm redoing it, with functions instead that I'll be able to call for the children c:
Oh, I do have a question though -- Do you know how I'd go about coding the probability of each gene being passed down to the children? Similar to how FR has rare genes, for instance. I'd like to make genes dominant and recessive, if possible!
@
XsvL8d thank you so much!!!
(And sorry about the late reply, I completely forgot to reply!)
Your answer pretty much confirmed that I've mostly been looking at the wrong things, making the breeding system based on genetical algorithms seems way too complicated :' )) The links you sent will help a lot! Especially the randrange, that one's gonna be perfect for when I start working for real on the breeding system.
Right now I'm currently recoding some of my script, I originally made a pet generator script with pillow to learn. It produced what I wanted to; a pet with the features the user picked, but it wasn't possible to base the breeding system on it since it didn't contain any functions. So now I'm redoing it, with functions instead that I'll be able to call for the children c:
Oh, I do have a question though -- Do you know how I'd go about coding the probability of each gene being passed down to the children? Similar to how FR has rare genes, for instance. I'd like to make genes dominant and recessive, if possible!
@notdura
flight rising has rarity tiers plentiful/common/uncommon/limited/rare that it uses for both breeds and genes. the most reader-friendly way i can think of is making two [url=https://docs.python.org/3/tutorial/datastructures.html#dictionaries]dictionaries[/url]
[code]gene_rarity['veined'] = 'limited'
rarity_comp['limited']['uncommon'] = 0.15 # probability of rolling first gene
rarity_comp['uncommon']['limited'] = 0.85[/code]
and fill in your variables as needed c:
edit: calling it would look something like
[code]child.primary = mother.primary
if random.random() < rarity_comp[gene_rarity[mother.primary]][gene_rarity[father.primary]]
else child.primary = father.primary[/code]
another way is to assign weights to each gene individually, but i used this for a hunger games sim and found it [i]way[/i] too frustrating to tweak if you're going to change it regularly.
for completeness' sake, one (sorta lame) implementation:
[code]eye_rarity = [('common', 50), ('uncommon', 25), ('unusual', 15), ('rare', 10), ('facet', 1), ('primal', 0.5), ('multigaze', 0.5), ('goat', 1)]
stop = random.uniform(0, sum([eye[1] for eye in eye_rarity]))
# or randrange if you're absolutely sure the total is an integer
for eye in eye_rarity:
if stop < eye[1]:
break
else:
stop -= eye[1]
print eye[0]
[/code]
@
notdura
flight rising has rarity tiers plentiful/common/uncommon/limited/rare that it uses for both breeds and genes. the most reader-friendly way i can think of is making two
dictionaries
Code:
gene_rarity['veined'] = 'limited'
rarity_comp['limited']['uncommon'] = 0.15 # probability of rolling first gene
rarity_comp['uncommon']['limited'] = 0.85
and fill in your variables as needed c:
edit: calling it would look something like
Code:
child.primary = mother.primary
if random.random() < rarity_comp[gene_rarity[mother.primary]][gene_rarity[father.primary]]
else child.primary = father.primary
another way is to assign weights to each gene individually, but i used this for a hunger games sim and found it
way too frustrating to tweak if you're going to change it regularly.
for completeness' sake, one (sorta lame) implementation:
Code:
eye_rarity = [('common', 50), ('uncommon', 25), ('unusual', 15), ('rare', 10), ('facet', 1), ('primal', 0.5), ('multigaze', 0.5), ('goat', 1)]
stop = random.uniform(0, sum([eye[1] for eye in eye_rarity]))
# or randrange if you're absolutely sure the total is an integer
for eye in eye_rarity:
if stop < eye[1]:
break
else:
stop -= eye[1]
print eye[0]
@
XsvL8d That's perfect, thank you so much for taking the time to help me learn!! <3
@
XsvL8d That's perfect, thank you so much for taking the time to help me learn!! <3
@
notdura no problem!! if you want to ask anything else feel free to hmu here
(also i stand corrected on the two dictionaries thing, rarity_comp would be a dictionary containing five other dictionaries to give that code sample. you can use a composite key and hardcode in every single combination, just remember to bundle the tuple with brackets first!)
@
notdura no problem!! if you want to ask anything else feel free to hmu here
(also i stand corrected on the two dictionaries thing, rarity_comp would be a dictionary containing five other dictionaries to give that code sample. you can use a composite key and hardcode in every single combination, just remember to bundle the tuple with brackets first!)