public override void Mutate(Random random, ExecutionEnvironment.Arr <int> field, int mutations) { for (int i = 0; i < mutations; i++) { int positionX = random.Next(0, field.W); int positionY = random.Next(0, field.H); int direction = random.Next(0, 2) == 0 ? -1 : 1; if (random.Next(0, 2) == 0) { // horizontal if (positionX == 0) { direction = 1; } if (positionX == field.W - 1) { direction = -1; } field.Swap(field.Coords(positionX, positionY), field.Coords(positionX + direction, positionY)); } else { // vertical if (positionY == 0) { direction = 1; } if (positionY == field.H - 1) { direction = -1; } field.Swap(field.Coords(positionX, positionY), field.Coords(positionX, positionY + direction)); } } }
public override void Mutate(Random random, ExecutionEnvironment.Arr <int> field, int mutations) { for (int i = 0; i < mutations; i++) { int positionX = random.Next(0, field.W); int positionY = random.Next(0, field.H); int diffX = random.Next(0, 2) == 0 ? -1 : 1; if (positionX == 0) { diffX = 1; } if (positionX == field.W - 1) { diffX = -1; } int diffY = random.Next(0, 2) == 0 ? -1 : 1; if (positionY == 0) { diffY = 1; } if (positionY == field.H - 1) { diffY = -1; } field.Swap(field.Coords(positionX, positionY), field.Coords(positionX + diffX, positionY + diffY)); } }
public override void Mutate(Random random, ExecutionEnvironment.Arr <int> field, int mutations) { ExecutionEnvironment.Arr <int> f = field.Clone(); int validPositionCount = 0; int pos = 0; for (int x = 0; x < field.W; x++) { for (int y = 0; y < field.H; y++) { if (8 > f.SimilarNeighbors(x, y, IncludeFieldBorders)) { f[pos] = -1; validPositionCount++; } pos++; } } mutations = Math.Min(mutations, validPositionCount); for (int i = 0; i < mutations; i++) { field.Swap(f.FreePosition(random.Next(0, validPositionCount), -1), f.FreePosition(random.Next(0, validPositionCount), -1)); } }
public override void Mutate(Random random, ExecutionEnvironment.Arr <int> field, int mutations) { for (int i = 0; i < mutations; i++) { field.Swap(random.Next(0, field.Length), random.Next(0, field.Length)); } }
public override void Mutate(Random random, ExecutionEnvironment.Arr <int> field, int mutations) { for (int m = 0; m < mutations; m++) { ExecutionEnvironment.Arr <int> f = field.Clone(); int startPos = random.Next(0, field.Length); int color = f[startPos]; int validPositionCount = markField(f, color, startPos); field.Swap(startPos, f.FreePosition(random.Next(0, validPositionCount), -1)); } }
public override void Mutate(Random random, ExecutionEnvironment.Arr <int> field, int mutations) { for (int m = 0; m < mutations; m++) { // remove invalid cells (cells with only neighbors of same color) ExecutionEnvironment.Arr <int> f = field.Clone(); int validCount = 0; for (int y = 0; y < f.H; y++) { for (int x = 0; x < f.W; x++) { if (field.NeighborsWithValueHV(field[x, y], x, y, 1, true) == 4) { f[x, y] = -1; } else { validCount++; } } } // choose start pos and color int startPos = f.ValidPosition(random.Next(0, validCount), -1); f[startPos] = -1; validCount--; int color = field[startPos]; ExecutionEnvironment.Arr <int> f2 = f.Clone(); // remove all cells that have no neighbor with matching color and cells with same color for (int y = 0; y < f.H; y++) { for (int x = 0; x < f.W; x++) { if (f[x, y] != -1 && (f[x, y] == color || f.NeighborsWithValueHV(color, x, y, 1, false) == 0)) { f2[x, y] = -1; validCount--; } } } // select target at random int targetPos = f2.ValidPosition(random.Next(0, validCount), -1); // swap field.Swap(startPos, targetPos); } }
public override void Mutate(Random random, ExecutionEnvironment.Arr <int> field, int mutations) { for (int i = 0; i < mutations; i++) { ExecutionEnvironment.Arr <int> f = field.Clone(); int validPositionCount = 0; int pos = 0; for (int y = 0; y < field.H; y++) { for (int x = 0; x < field.W; x++) { if (8 > f.SimilarNeighbors(x, y, IncludeFieldBorders)) { f[pos] = -1; validPositionCount++; } pos++; } } int steps = random.Next(1, validPositionCount); int position = f.FreePosition(random.Next(0, validPositionCount), -1); int xPos = position % field.W; int yPos = position / field.W; int processor = f[position]; for (int i2 = 0; i2 < steps; i2++) { f[position] = -1; int next = f.NextPosition(random, processor, -1, xPos, yPos); if (next == -1) { break; } field.Swap(position, next); position = next; } } }