private LinkedList <INode> RemoveChildsByBoxSpread(LinkedList <INode> boxList) { LinkedList <INode> result = new LinkedList <INode>(); bool spreadFaultFound; foreach (var box in boxList) { BoxOD b = (BoxOD)box; spreadFaultFound = false; for (int i = 0; i < b.snakes.Length; i++) //i snake { for (int j = 0; j < b.snakes.Length; j++) //j snake { if (i == j) { continue; } for (int k = 0; k < b.snakes[j].tail.Length; k++) { if (World.HammingDistance(b.snakes[i].Head, b.snakes[j].tail[k]) < world.BoxSpread) { spreadFaultFound = true; break; } } if (spreadFaultFound) { break; } } if (spreadFaultFound) { break; } } if (!spreadFaultFound) { result.AddLast(b); } } return(result); }
public List <int> GetSnakeSpreadFreeSpots() { List <int> freeSpots = new List <int>(); for (int i = 0; i < world.MaxPlacesInDimention; i++) { bool valid = true; foreach (var part in tail) { if (World.HammingDistance(i, part) < world.SnakeSpread) { valid = false; break; } } if (valid) { freeSpots.Add(i); } } return(freeSpots); }
private LinkedList <INode> removeChildsWithBadHeadSpread(LinkedList <INode> childs) { LinkedList <INode> result = new LinkedList <INode>(); bool found; foreach (var child in childs) { Snake c = (Snake)child; found = false; for (int i = 0; i < c.tail.Length - world.SnakeSpread; i++) { if (World.HammingDistance(c.Head, c.tail[i]) < world.SnakeSpread) { found = true; break; } } if (!found) { result.AddLast(c); } } return(result); }
public static bool ValidOneStepOfSnake(int a, int b) { return(World.HammingDistance(a, b) == 1); }