public MutantForm(Mutant mutant) { InitializeComponent(); textBoxInstructions.Text = mutant.ReadableInstructions(); }
public int Replicate(int sourceId, int destinationId, int maxMutatedBytes) { Random random = new Random(); var sourceMutant = mutants[sourceId]; var newBytes = sourceMutant.BytesList(); int mutatedBytes = random.Next(maxMutatedBytes + 1); for (int i = 0; i < mutatedBytes; ++i) { var mutateMethod = random.Next(6); var position = random.Next(dbContext.MutantSize); switch (mutateMethod) { case 0: case 1: { var value = (byte)random.Next(0, 256); newBytes[position] = value; } break; case 2: { var value = (byte)random.Next(0, 256); newBytes.RemoveAt(position); newBytes.Add(value); } break; case 3: { var value = (byte)random.Next(0, 256); newBytes.Insert(position, value); newBytes.RemoveAt(mutatedBytes); } break; case 4: // Copy { var source = random.Next(0, dbContext.MutantSize); if (source != position) { newBytes[position] = newBytes[source]; } } break; case 5: // Swap { var other = random.Next(0, dbContext.MutantSize); if (other != position) { var temp = newBytes[position]; newBytes[position] = newBytes[other]; newBytes[other] = temp; } } break; } } mutants[destinationId] = new Mutant(destinationId, newBytes.ToArray()); return(mutatedBytes); }