Generation Turnament: Explanations
Tit for Tat Evolution Strategies

How to configure the Generation turnament

To configure tnew strategies, modify the file generations.js that is given with all the other file in the .zIP archive at the page download.
In that file it is possible to configure:
1. number of generations
2. percentage points necessary to survive

Open the file with a text editor (Notepad o similar), and you will find immediately the first two parameters:

generazioni=10; (generations)
percentuale=85;
(percentage)

The turnaments will run for 8 generations, the number can be increased avoiding to slow down too mutch the PC. Sometime th ebrower can ask to interrupt the script, but by pressing continue most of the cases the script will work. Save and open data before running the script to avoid loosing them if you will need to reset the PC.
85 indicates the percentage of the score that the strategies will get if both will always cooperate. If the final score is lower, the strategy will evolve in something else.

How the script works

After the configuration of the custom parameters, the actual situation will be displayed:

document.write(percentuale+"% is the percentage of the score if both the opponents was always cooperating that is necessary for the strategy to suvive.");
percentuale=percentuale/100;
document.write(" Minimum score ="+cicli*tot*3*percentuale);

Next, the cycle that will be repeated for all the generations will start:

for (gen = 2; gen <= generazioni; gen++)
{

Then the cycle that checks the score that each strategy obtained in the previous turnament:

for (x = 1; x <= tot; x++)
{
if (punti[x]<=cicli*tot*3*percentuale) {

If the score is below the presetted percentage, the strategy wil change:

nome[x]="Mutation of "+nome[x];

mutaAP=DNA[x].substr(2,1); // extract the 3rd character
mutaSTR=DNA[x].substr(3,3); // extract the 4,5,6 characters

mutazione=Math.floor(Math.random()*2);
if (mutazione==1) {
switch (mutaAP)
{case "A": mutaAP="C";break
case "T": mutaAP="G";break
case "C": mutaAP="T";break
default: mutaAP="A";
}
}

if (mutazione==0) {
switch (mutaSTR)
{case "TTT": mutaSTR="TTG";break
case "TTG": mutaSTR="AAG";break
case "AAG": mutaSTR="AAA";break
case "AAA": mutaSTR="TTA";break
case "TTA": mutaSTR="TTC";break
case "TTC": mutaSTR="AAC";break
case "AAC": mutaSTR="TTT";break
}
}

DNA[x]=DNA[x].substr(0,1)+"U"+mutaAP+mutaSTR+DNA[x].substr(6,2);
// note: the second character mutate in U

}
}

With the code above, we extract some part of the DNA, than randomly is decidet if the character number 3,4,5 or 6 will change.
As indicated, if the first character will change, if it was an "A" it will become "C", or a "T" will become a "G" and so on.
If the strategy will change, if it was "TTT", it will change in "TTG", or "TTG" will become "AAG" and so on.

situazione ();
torneo ();
classifica ();
}

The above functions will be then run:
situazione will be explaned below, then the turnament and the classification that are the same functions explained in the single turnament page.

Let's see the last function situazione () were the changed DNA will be displayes.

function situazione ()
{
document.write("<table summary='mutanti' border=1 align='center'>");

document.write("<tr><td colspan=2>Mutations of generation number "+gen+"<\/b><\/td><\/tr>");

// begin cycle for nr names
for (x = 1; x <= tot; x++) {

// extracts first gene ** colour **
colore[x]=DNA[x].substr(0,1); // extracts 1st character
switch (colore[x])
{case "A": colore[x]="green";break
case "C": colore[x]="yellow";break
case "G": colore[x]="orange";break
case "T": colore[x]="red";break
default: document.write("
* Error 1 on DNA of "+[x]+" * ");
}
// extracts second gene ** mutation **
controllo=DNA[x].substr(1,1); // estracts the 2nd character
if (controllo=="U") {colore[x]="blue"};

document.write("<tr><td bgcolor='"+colore[x]+"' valign='top'>");
document.write(x+") "+nome[x]+"");
document.write("<td>DNA="+DNA[x]+"<\/td><\/tr>");
} document.write("<\/table>");
}

Back to this article index

Go to the generations turnaments