Documentation ¶
Index ¶
- type Box
- func (box *Box) CalculateFitness()
- func (box *Box) CheckCollision(walls []utils.Obstacle)
- func (box *Box) Crossover(partner Box) (Box, Box)
- func (box *Box) Draw(screen *ebiten.Image)
- func (box *Box) Mutate()
- func (box *Box) Reset()
- func (box *Box) SetGenes(genes []utils.Vector)
- func (box *Box) Update(counter int)
- type DNA
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Box ¶
type Box struct { IsAlive bool AliveTime int Position utils.Vector Size int Fitness float64 Won bool Acceleration utils.Vector Velocity utils.Vector Traveled float64 Genes DNA Dist float64 Frames int }
Box represents an individual in the population.
func (*Box) CalculateFitness ¶
func (box *Box) CalculateFitness()
CalculateFitness calculates the fitness of the box based on its position, distance to the goal, and other factors. It updates the Fitness field of the box. Returns: none.
func (*Box) CheckCollision ¶
CheckCollision checks if the box collides with any walls or goes out of the game boundaries. If a collision is detected, the box's IsAlive flag is set to false. Parameters: - walls: a slice of engine.Obstacle representing the walls in the game. Returns: none.
func (*Box) Crossover ¶
Crossover applies crossover to the Box's genes based on the crossover rate specified in the settings. If the crossover rate is met, the Box's genes are crossed with the partner's genes. The crossover point is randomly selected. The new genes are created by combining the genes of the Box and the partner. Returns: two new Box objects with the new genes.
func (*Box) Mutate ¶
func (box *Box) Mutate()
Mutate applies mutation to the Box's genes based on the mutation rate specified in the settings. If the mutation rate is met, a random gene in the Box's gene chain is selected and its X or Y value is multiplied by 1.01. The mutation quantity is set to 1 by default.
type DNA ¶
DNA of the individual. It contains the genes of the individual.