Traitor 1.0.1

.NET Standard 1.3
NuGet\Install-Package Traitor -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package Traitor --version 1.0.1
<PackageReference Include="Traitor" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Traitor --version 1.0.1
#r "nuget: Traitor, 1.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Traitor as a Cake Addin
#addin nuget:?package=Traitor&version=1.0.1

// Install Traitor as a Cake Tool
#tool nuget:?package=Traitor&version=1.0.1

Traitor trait library

This project aims to provide a simple algorithm neatly packaged and usable for genetic algorithms though primarily aimed at game development.

The algorithm it implements is one that picks random traits from one or more parents into a new set of genes with a chance of random mutation and novel traits.


This project is based primarily on two classes: Genes<TKey, TValue> and GeneCombiner<TKey, TValue>. The generic arguments indicate the type on the trait key and trait value. A trait key, TKey, is usually either a string or an int. The trait value, TValue, is usually either int or double.

A new set of genes is created using Gene<TKey, TValue>'s constructor which takes an IEnumerable<Trait<string, int>>.

var genes = new Genes<string, int>(new[] { new Trait<string, int>("funk", 10) });

If you, for whatever reason, need an empty gene set use Gene<TKey, TValue> use the static property Gene<TKey, TValue>.Empty. This value is a singleton, but Gene<TKey, TValue> is an immutable type so it shouldn't matter.

The GeneCombiner<TKey, TValue> is used to combine genes or at the very least create a somewhat random offspring of one or more sets of genes. It is initialized through its constructor and you likely just need one instance. By default it uses a thread static Random instance and should be thread safe.

The most demanind constructor requires a random function, a novel trait function, a trait mutation function, trait mutation chance and finally a novel trait chance.

The random function simply a function that returns a random number. When this is omitted it will use System.Random.

After the random functio you can provide a trait factory. This is the factory to produce a novel trait. It takes in an IEnumerable of the current traits and returns a novel trait. The input argument can be used to make sure that a novel trait is always returned if possible.

Following is a mutation function, or "mutationValue" function. This takes the current trait and returns the new trait value. This parameter must always be provided. Some examples are provided in the Mutators class. The Hello World example uses Mutators.Gaussian.

Then you have trait mutation chance which is a rational. The rational type has an implicit cast from tuple so for a 1/100 chance simply write (1, 100).

Following that is the novel trait chance. This follows trait mutation chance.

When an instance is available you can use the Combine function to produce "offspring". It takes at least one set of genes (for asexual reproduction I guess) but you can provide as many sets as you like. It will always produce a single instance.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 netstandard2.1
.NET Framework net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen30 tizen40 tizen60
Universal Windows Platform uap uap10.0
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 478 12/17/2018

# Traitor release notes

## v1.0.1 Update license in nuget package

* Minor non-functional changes in project structure.

## v1.0.0 Initial Release

* Implemented Genes which is a set of genes

* Implemented GeneCombiner which produce a new set of genes from one or more other genes.

* Unit test coverage