public TestGenome(GameConstants consts, Random rnd, IGenome a, IGenome b) { //g = new ManGenome(consts, rnd, a, b); int seed = rnd.Next(); Random mrnd = new Random(seed); Random brnd = new Random(seed); ManGenome mg = new ManGenome(consts, mrnd, ((TestGenome)a).g, ((TestGenome)b).g); BarrGenome bg = new BarrGenome(consts, brnd, a, b); for (int i = 0; i < mg.length; i++) { if (bg[i] != mg[i]) { throw new Exception("err"); } for (int j = 0; j <= 32 && i + j < mg.length; j++) { if (bg.cutOutInt(i, j) != mg.cutOutInt(i, j)) { throw new Exception("err " + i + " " + j); } } } foreach (bool bbb in mg) { g = mg; } g = mg; }
private void addSpecimen(ManGenome g) #endif { Specimen s = new Specimen(g, consts); resetSpecimen(s); s.computeFitness(); specimens.Add(s); }
public Specimen(ManGenome gN, GameConstants consts) #endif { g = gN; fitnessScoreCoef = consts.fitnessScoreCoef; }
// I hate this method public ManGenome(GameConstants consts, Random rnd, ManGenome a, ManGenome b) : this(consts) { ManGenome cur = a; ManGenome oth = b; uint curi = cur.ints[0]; uint othi = oth.ints[0]; Action swap = () => { var t = cur; cur = oth; oth = t; var ti = curi; curi = othi; othi = ti; }; if (rnd.NextDouble() < 0.5) { swap(); } int ii = 0; int ij = 0; uint ib = 1; uint c = 0; for (int i = 0; i < glen; i++) { if (ib == 0) { ints[ii++] = c; c = 0; ij = 0; ib = 1; curi = cur.ints[ii]; othi = oth.ints[ii]; } uint v = (curi & ib); if (rnd.NextDouble() < consts.genomeMutateRate) { v ^= ib; } c |= v; if (rnd.NextDouble() < consts.genomeSwapRate) { swap(); } ij++; ib = ib << 1; } ints[ii] = c; }
public TestGenome(GameConstants consts, Random rnd) { g = new ManGenome(consts, rnd); }