genetics

package module
v0.0.0-...-ac9a7a9 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: GPL-3.0 Imports: 1 Imported by: 4

README

genetics: Heredity and gene mixing

This package provides 64 bit gene sequences as well as the ability to manipulate and mix them for various simulation or procedural generation purposes.

It is nothing fancy, but it does the trick. I have set up an example that encodes some human-ish properties.

Example gene layout

  _______________________ 2 gender
 || _____________________ 2 eye color
 ||||  __________________ 3 hair color         ___________________________ 4 Openness
 |||| ||| _______________ 4 complexion        ||||  ______________________ 4 Conscientiousness
 |||| |||| ||| __________ 3 height            |||| |||| __________________ 4 Extraversion
 |||| |||| |||| || ______ 3 mass              |||| |||| ||||  ____________ 4 Agreeableness
 |||| |||| |||| |||| | __ 3 growth            |||| |||| |||| ||||  _______ 4 Neuroticism
 |||| |||| |||| |||| ||||                     |||| |||| |||| |||| ||||
 xxxx xxxx|xxxx xxxx|xxxx xxxx|xxxx xxxx|xxxx xxxx|xxxx xxxx|xxxx xxxx|xxxx xxxx
                          |||| |||| |||| ||||                          |||| ||||
 4 strength _________________  |||| |||| ||||                           ________ unused
 4 intelligence __________________  |||| ||||
 4 dexterity __________________________  ||||
 4 resilience ______________________________

Documentation

Overview

Package genetics provides a simple framework for gene mixing / editing for procedural generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gene

type Gene struct {
	NumBits int
	Offset  int
}

func (*Gene) MaxVal

func (g *Gene) MaxVal() int

type Genes

type Genes uint64

func Mix

func Mix(a, b Genes, nMutations int) Genes

Mix combines the two sets of genes by using the bits in common in both sets as baseline and then randomly sets bits that are different in both sets. Additional a number of mutations can be applied which randomly flip bits.

func NewRandom

func NewRandom() Genes

NewRandom returns a randomized set of genes.

func (*Genes) Get

func (g *Genes) Get(d Gene) int

Get the value of gene 'd'.

func (*Genes) Set

func (g *Genes) Set(d Gene, val int)

Set the gene 'd' to the supplied value.

type Pool

type Pool struct {
	Rand *rand.Rand
}

Pool provides means to use a set seed for gene generation/mixing.

func NewPool

func NewPool(seed int64) *Pool

NewPool initializes a gene pool with the given seed.

func (*Pool) Mix

func (p *Pool) Mix(a, b Genes, nMutations int) Genes

Mix combines the two sets of genes by using the bits in common in both sets as baseline and then randomly sets bits that are different in both sets. Additional a number of mutations can be applied which randomly flip bits.

func (*Pool) NewRandom

func (p *Pool) NewRandom() Genes

NewRandom returns a randomized set of genes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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