Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

be_ai_gen.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions

int GeneticParentsAndChildSelection (int numranks, float *ranks, int *parent1, int *parent2, int *child)


Function Documentation

int GeneticParentsAndChildSelection int  numranks,
float *  ranks,
int *  parent1,
int *  parent2,
int *  child
 

Definition at line 90 of file be_ai_gen.c.

References botimport, Com_Memcpy(), GeneticSelection(), i, max, and PRT_WARNING.

00091 {
00092     float rankings[256], max;
00093     int i;
00094 
00095     if (numranks > 256)
00096     {
00097         botimport.Print(PRT_WARNING, "GeneticParentsAndChildSelection: too many bots\n");
00098         *parent1 = *parent2 = *child = 0;
00099         return qfalse;
00100     } //end if
00101     for (max = 0, i = 0; i < numranks; i++)
00102     {
00103         if (ranks[i] < 0) continue;
00104         max++;
00105     } //end for
00106     if (max < 3)
00107     {
00108         botimport.Print(PRT_WARNING, "GeneticParentsAndChildSelection: too few valid bots\n");
00109         *parent1 = *parent2 = *child = 0;
00110         return qfalse;
00111     } //end if
00112     Com_Memcpy(rankings, ranks, sizeof(float) * numranks);
00113     //select first parent
00114     *parent1 = GeneticSelection(numranks, rankings);
00115     rankings[*parent1] = -1;
00116     //select second parent
00117     *parent2 = GeneticSelection(numranks, rankings);
00118     rankings[*parent2] = -1;
00119     //reverse the rankings
00120     max = 0;
00121     for (i = 0; i < numranks; i++)
00122     {
00123         if (rankings[i] < 0) continue;
00124         if (rankings[i] > max) max = rankings[i];
00125     } //end for
00126     for (i = 0; i < numranks; i++)
00127     {
00128         if (rankings[i] < 0) continue;
00129         rankings[i] = max - rankings[i];
00130     } //end for
00131     //select child
00132     *child = GeneticSelection(numranks, rankings);
00133     return qtrue;
00134 } //end of the function GeneticParentsAndChildSelection

Here is the call graph for this function:


Generated on Thu Aug 25 13:45:50 2005 for Quake III Arena by  doxygen 1.3.9.1