Christopher Ek

Natural Selection [python, algo, fitness, mutation]

Published 2022-02-0920 min read0 comments

General idea

Concept

Some type of "playground" is required. We may employ Python's secret weapon.... lists, We make a 100x100 two-dimensional array, thus the ARRAY variable gets the scope

\(arr[0-100][0-100]\)

It's easy to visualize the "playground" looking like a tic-tac-toe board. Instead of the 3x3 squares used in tic-tac-toe, we use 100x100 squares instead to simulation land/hunting-ground."
This simulation is meant to simulate the relation between hunter and prey, and see how we can use natural selection, or more technical fitness functions and mutation. This topics will be explain further down don't you worry.



TLDR (for people with no attention-span)

We put weight on certain attribtures depnding on how well they performed during the iteration.

Example 01

Prey 01 survived with 150hp, but Prey 02 survived with 120hp. Prey01's genes are given a higher weight. We take the top half of the class and couple them up. This will generate two children with mutating DNA. Genes from both XX and XY will be found in the childern.

End Goal

The ultimate objective is to see if the prey can outlast the hunter. Also I wanna see if prey can turn into hunters but that's for version 2.0

Video Explanation (poor quality.)





Agents

Prey

I need to create an attribute list for prey. What every "fitness parameter" does in practice.
Ex: If your speed attribute/rating is 52, for example. And I have a regulation that states if your speed is beyond 50, you...
Increase your chances of escaping an attack by 15%.

I need to declare this ahead of time so that I may adjust the fitenss/mutation subroutines more easily.

GEN POOL

Gen 0: Health (How much health tbey have.)
Gen 1: Weight (How much damage they take)
Gen 2: attack power (This will always be 0)
Gen 3: Speed (How good they are at evading prey.)
Gen 4: Age (Decay)
Days Survived: How many iterations the prey has survived.
Enemy Close: How many times was the prey within X amount of blocks of hunter. (Day to day basis)

FITNESS FUNCTION

Hunter

GEN POOL

Gen 0: Health (How much health tbey have.)
Gen 1: Weight (How much damage they take)
Gen 2: attack power (How much damage they do.)
Gen 3: Speed (How fast they perform damage.)
Gen 4: Age (Decay)
Feral Mode: Bool -> if the hunter kills at least three prey the night before.

FITNESS FUNCTION

Advanced Information

fitness function

I haven't done a lot of research on fitness functions. I think I'll have around 3 hours of study time dedicated to the topic A fitness function's purpose is to determine how well something performed on a given task. So, if the assignment is to travel from point A to point B, as quick as possible. The "object" with the greatest fitness score will be the object who completes the job the fastest. In our situation, we look at prey survival rates and which characteristics cause the greatest harm and success when it comes to survival.

mutation function

Enviornment Class

I constructed a class called Environment, which is in charge of population and generation of agents.

UNDER PROGRESS... NOT COMPLETE(free-flowing updates)