public static bool IsEmpty(CellStruct cell) { if (cell.type > 17) { return(true); } return(false); }
public static bool HasWeapon(int x, int y, List <CellStruct> listCells) { CellStruct cell = listCells.FirstOrDefault(c => c.x == x && c.y == y); if (cell == null) { return(false); } return(HasWeapon(cell)); }
public static bool HasSkeleton(CellStruct cell) { int j = cell.type; if (j == 6 || j == 7 || j == 8) { //Skeleton return(true); } return(false); }
public static bool HasMummy(CellStruct cell) { int j = cell.type; if (j == 3 || j == 4 || j == 5) { //Mummy return(true); } return(false); }
public static bool HasTurtle(CellStruct cell) { int j = cell.type; if (j == 0 || j == 1 || j == 2) { //Turtle return(true); } return(false); }
public static bool HasItem(CellStruct cell) { int j = cell.type; if (j == 9) { //Rapier return(true); } else if (j == 10) { //Battle Axe return(true); } else if (j == 11) { //Potion return(true); } else if (j == 12) { //Borra return(true); } else if (j == 13) { //Bread return(true); } else if (j == 14) { //Leather cap return(true); } else if (j == 15) { //Leather brigandine return(true); } else if (j == 16) { //Leather pants return(true); } else if (j == 17) { //Leather boots return(true); } return(false); }
protected bool AreEquals(CellStruct c, CellStruct originalCell) { if (HasArmor(c) && HasArmor(originalCell) || HasResource(c) && HasResource(originalCell) || HasWeapon(c) && HasWeapon(originalCell) || HasMummy(c) && HasMummy(originalCell) || HasTurtle(c) && HasTurtle(originalCell) || HasSkeleton(c) && HasSkeleton(originalCell) || IsEmpty(c) && IsEmpty(originalCell)) { return(true); } return(false); }
public static bool HasWeapon(CellStruct cell) { int j = cell.type; if (j == 9) { //Rapier return(true); } else if (j == 10) { //Battle Axe return(true); } return(false); }
public static bool HasMonster(CellStruct cell) { int j = cell.type; if (j == 0 || j == 1 || j == 2) { //Turtle return(true); } else if (j == 3 || j == 4 || j == 5) { //Mummy return(true); } else if (j == 6 || j == 7 || j == 8) { //Skeleton return(true); } return(false); }
public static bool HasResource(CellStruct cell) { int j = cell.type; if (j == 11) { //Potion return(true); } else if (j == 12) { //Borra return(true); } else if (j == 13) { //Bread return(true); } return(false); }
private void Mutate(Chromosome child) { Chromosome childToMutate = null; if (AllowDuplicates) { childToMutate = child; } else { //We have to clone the chromosome before we mutate it as it may //not be usable i.e. if it is a duplicate if we didn't clone it //and we created a duplicate through mutation we would have to //undo the mutation. This way is easier. childToMutate = new Chromosome(child.Genes); } //call the default mutation behaviour //cannot mutate elites or else we will ruin them if (childToMutate.IsElite) { return; } if (childToMutate == null || childToMutate.Genes == null) { throw new ArgumentException("The Chromosome is either null or the Chromosomes Genes are null."); } string binaryString = childToMutate.ToBinaryString(); int count = binaryString.Length / Interval; for (int i = 0; i < count; i++) { string s = binaryString.Substring(i * Interval, Interval); int type = Convert.ToInt32(s, 2); CellStruct tmpCell = new CellStruct(type, 0, 0); if (HasMonster(tmpCell)) { var rd = RandomProvider.GetThreadRandom().NextDouble(); if (rd <= MutationProbability) { int index = i * Interval; var rdType = RandomProvider.GetThreadRandom().Next(0, 3); if (rdType == 0) { // 1 : 00000001 childToMutate.Genes[index].ObjectValue = false; childToMutate.Genes[index + 1].ObjectValue = false; childToMutate.Genes[index + 2].ObjectValue = false; childToMutate.Genes[index + 3].ObjectValue = false; childToMutate.Genes[index + 4].ObjectValue = false; childToMutate.Genes[index + 5].ObjectValue = false; childToMutate.Genes[index + 6].ObjectValue = false; childToMutate.Genes[index + 7].ObjectValue = true; } else if (rdType == 1) { // 12 : 00001100 childToMutate.Genes[index].ObjectValue = false; childToMutate.Genes[index + 1].ObjectValue = false; childToMutate.Genes[index + 2].ObjectValue = false; childToMutate.Genes[index + 3].ObjectValue = false; childToMutate.Genes[index + 4].ObjectValue = true; childToMutate.Genes[index + 5].ObjectValue = true; childToMutate.Genes[index + 6].ObjectValue = false; childToMutate.Genes[index + 7].ObjectValue = false; } else { // 23 : 00010111 childToMutate.Genes[index].ObjectValue = false; childToMutate.Genes[index + 1].ObjectValue = false; childToMutate.Genes[index + 2].ObjectValue = false; childToMutate.Genes[index + 3].ObjectValue = true; childToMutate.Genes[index + 4].ObjectValue = false; childToMutate.Genes[index + 5].ObjectValue = true; childToMutate.Genes[index + 6].ObjectValue = true; childToMutate.Genes[index + 7].ObjectValue = true; } } } } /*for (int i = 0; i < childToMutate.Genes.Count; i++) * { * if (IsMarked(i, binaryString)) * { * //check probability by generating a random number between zero and one and if * //this number is less than or equal to the given mutation probability * //e.g. 0.001 then the bit value is changed. * var rd = RandomProvider.GetThreadRandom().NextDouble(); * * if (rd <= MutationProbability) * { * MutateGene(childToMutate.Genes[i]); * } * } * }*/ //only add the mutated chromosome if it does not exist otherwise do nothing if (!AllowDuplicates && !NewPopulation.SolutionExists(childToMutate)) { //swap existing genes for the mutated onese child.Genes.Clear(); child.Genes.AddRangeCloned(childToMutate.Genes); } }
public static bool HasSkeleton(int x, int y, List <CellStruct> listCells) { CellStruct cell = listCells.FirstOrDefault(c => c.x == x && c.y == y); return(HasSkeleton(cell)); }