// Parameter: - // Returns: - // Changes Globals: - // =========================================================================== int GeneticParentsAndChildSelection(int numranks, float *ranks, int *parent1, int *parent2, int *child) { float rankings[256], max; int i; if (numranks > 256) { botimport.Print(PRT_WARNING, "GeneticParentsAndChildSelection: too many bots\n"); *parent1 = *parent2 = *child = 0; return qfalse; } for (max = 0, i = 0; i < numranks; i++) { if (ranks[i] < 0) { continue; } max++; } if (max < 3) { botimport.Print(PRT_WARNING, "GeneticParentsAndChildSelection: too few valid bots\n"); *parent1 = *parent2 = *child = 0; return qfalse; } memcpy(rankings, ranks, sizeof(float)* numranks); // select first parent *parent1 = GeneticSelection(numranks, rankings); rankings[*parent1] = -1; // select second parent *parent2 = GeneticSelection(numranks, rankings); rankings[*parent2] = -1; // reverse the rankings max = 0; for (i = 0; i < numranks; i++) { if (rankings[i] < 0) { continue; } if (rankings[i] > max) { max = rankings[i]; } } for (i = 0; i < numranks; i++) { if (rankings[i] < 0) { continue; } rankings[i] = max - rankings[i]; } // select child *child = GeneticSelection(numranks, rankings); return qtrue; } // end of the function GeneticParentsAndChildSelection
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int GeneticParentsAndChildSelection(int numranks, gfixed *ranks, int *parent1, int *parent2, int *child) { gfixed rankings[256], max; int i; if (numranks > 256) { botimport.Print(PRT_WARNING, "GeneticParentsAndChildSelection: too many bots\n"); *parent1 = *parent2 = *child = 0; return qfalse; } //end if for (max = GFIXED_0, i = 0; i < numranks; i++) { if (ranks[i] < GFIXED_0) continue; max++; } //end for if (max < GFIXED(3,0)) { botimport.Print(PRT_WARNING, "GeneticParentsAndChildSelection: too few valid bots\n"); *parent1 = *parent2 = *child = 0; return qfalse; } //end if Com_Memcpy(rankings, ranks, sizeof(gfixed) * numranks); //select first parent *parent1 = GeneticSelection(numranks, rankings); rankings[*parent1] = -GFIXED_1; //select second parent *parent2 = GeneticSelection(numranks, rankings); rankings[*parent2] = -GFIXED_1; //reverse the rankings max = GFIXED_0; for (i = 0; i < numranks; i++) { if (rankings[i] < GFIXED_0) continue; if (rankings[i] > max) max = rankings[i]; } //end for for (i = 0; i < numranks; i++) { if (rankings[i] < GFIXED_0) continue; rankings[i] = max - rankings[i]; } //end for //select child *child = GeneticSelection(numranks, rankings); return qtrue; } //end of the function GeneticParentsAndChildSelection