population

package
v0.0.0-...-520183b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

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 NewBox

func NewBox(genes *DNA) *Box

NewBox creates a new Box object with the given genes.

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

func (box *Box) CheckCollision(walls []utils.Obstacle)

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

func (box *Box) Crossover(partner Box) (Box, Box)

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) Draw

func (box *Box) Draw(screen *ebiten.Image)

Draw draws the Box on the screen.

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.

func (*Box) Reset

func (box *Box) Reset()

Reset resets the state of the Box.

func (*Box) SetGenes

func (box *Box) SetGenes(genes []utils.Vector)

SetGenes sets the genes of the Box.

func (*Box) Update

func (box *Box) Update(counter int)

Update updates the state of the Box.

type DNA

type DNA struct {
	Chain []utils.Vector
}

DNA of the individual. It contains the genes of the individual.

func (*DNA) NewDNA

func (dna *DNA) NewDNA(genes []utils.Vector) *DNA

NewDNA creates a new DNA object with the given genes If genes is nil, it will create a new DNA object with random genes If genes is not nil, it will create a new DNA object with the given genes The genes are a sequence of random numbers that represent the path

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL