Implementation The Genome Module

MandarJ

New Member
Contributor
This article is a high-level description of the Genome module.

Purpose

The Genome module aims to be a way to add diversity to various breeding species by implementing a genetics. Each individual of a breeding species has a genome which contains a sequence of genes. Each gene governs a certain hereditary trait of the individual. When two such individuals breed, the gene sequences of the two individuals involved are combined according to a breeding algorithm to obtain the genome of the resulting offspring. Note that the offspring's genome and the parents' genomes must be of the same type and should have the same number of genes. Only the values of the genes can be different.

Structure

The primary building block of the Genome module is the Genome Component. This component must be present on all organisms which can breed, and must contain the following two fields:
  • genomeId: The type ID of the genome. This field is used to determine the genome definition of the genome, and to determine whether two given genome components can be combined.
  • genes: This String contains an ordered sequence of the values of the genes of the organism. These genes are used to determine hereditary characteristics of the individual, and are combined with another individual's genes during breeding to determine the genes of the offspring.
Each genome type corresponds to a certain Genome Definition. This object common properties of all genes of the given type, namely the breeding algorithm used and the genome map of genes of the type (the genome map is used to determine what property of the individual a certain gene governs).

The module also introduces a new component system: the Genome Registry. This component system contains a map between genome type IDs and the corresponding genome definitions, and is used to get the genome definition for a given type and to register new genome types.

The main mechanism used by the Genome module during breeding consists of various Breeding Algorithms. Breeding algorithms are classes which implement the Breeding Algorithm interface. These classes must define two methods:
  • canCross(String, String): This method determines whether two given gene sequences can be crossed to form an offspring.
  • produceCross(String, String): This method produces a gene sequence produced by crossing two given parent gene sequences.
A Genome Manager interface is also defined. Genome managers combine all the systems described above and interface them with the actual entity system. They define methods which use the above mentioned objects to determine whether two given organisms can breed and to cross the genomes of the given organisms according to an appropriate breeding algorithm to generate the genome component of the offspring and to add the component to the offspring entity.

Extensibility

The Genome module is a general infrastructure for breeding species. A great advantage of this is that it is not specific to any specific kind of species for which this system can be implemented. Thus, other modules can use this module by adding their own breeding algorithms and gene types, and then connecting those to actual in-game features of species like plants, animals, etc. Note that this system does not require that the species it is implemented for be animate. One could also enable this system for non-living objects if so desired.

Another prospect for extensibility is the ability to add new generic breeding algorithms and genome managers. New breeding algorithms can be added by adding a class which implements the Breeding Algorithm interface and defines the required methods, namely String canCross(String, String) and String produceCross(String, String), where the given Strings are the gene sequences of the parents. New genome managers can be added by implementing the Genome Manager interface and implementing the required methods (see the Genome Manager interface).
 

MandarJ

New Member
Contributor
@smsunarto sure. Just tell me what your new module does (on irc maybe). Also, do we really need a new module? We could just continue expanding SimpleFarming.
 
Top