//Search for a case around given case private ARX.Direction oneRandAdjacent(int baseSearch) { //Decide in which order directions will be tested List <ARX.Direction> possibilities = new List <ARX.Direction> { ARX.Direction.Up, ARX.Direction.Right, ARX.Direction.Down, ARX.Direction.Left }; ARX.Shuffle(rand, possibilities); //Test all directions foreach (ARX.Direction test in possibilities) { if (test == ARX.Direction.Up && Upper(baseSearch) != null) { return(ARX.Direction.Up); } else if (test == ARX.Direction.Right && Righter(baseSearch) != null) { return(ARX.Direction.Right); } else if (test == ARX.Direction.Down && Lower(baseSearch) != null) { return(ARX.Direction.Down); } else if (test == ARX.Direction.Left && Lefter(baseSearch) != null) { return(ARX.Direction.Left); } } return(ARX.Direction.Null); }
//Search for an empty case around given case private List <ARX.Direction> someRandAdjacent(int baseSearch) { //Decide in which order directions will be tested List <ARX.Direction> possibilities = new List <ARX.Direction> { ARX.Direction.Up, ARX.Direction.Right, ARX.Direction.Down, ARX.Direction.Left }; if (!(Upper(baseSearch) != null)) { possibilities.Remove(ARX.Direction.Up); } if (!(Righter(baseSearch) != null)) { possibilities.Remove(ARX.Direction.Right); } if (!(Lower(baseSearch) != null)) { possibilities.Remove(ARX.Direction.Down); } if (!(Lefter(baseSearch) != null)) { possibilities.Remove(ARX.Direction.Left); } ARX.Shuffle(rand, possibilities); possibilities.RemoveRange(0, (int)Math.Ceiling(possibilities.Count / 2.0)); return(possibilities); }
//Search for an empty case around given case private List <ARX.Direction> allRandEmpty(int baseSearch) { //Decide in which order directions will be tested List <ARX.Direction> possibilities = new List <ARX.Direction> { ARX.Direction.Up, ARX.Direction.Right, ARX.Direction.Down, ARX.Direction.Left }; if (!(Upper(baseSearch) != null && Upper(baseSearch).State == ARX.State.Void)) { possibilities.Remove(ARX.Direction.Up); } if (!(Righter(baseSearch) != null && Righter(baseSearch).State == ARX.State.Void)) { possibilities.Remove(ARX.Direction.Right); } if (!(Lower(baseSearch) != null && Lower(baseSearch).State == ARX.State.Void)) { possibilities.Remove(ARX.Direction.Down); } if (!(Lefter(baseSearch) != null && Lefter(baseSearch).State == ARX.State.Void)) { possibilities.Remove(ARX.Direction.Left); } ARX.Shuffle(rand, possibilities); return(possibilities); }
protected override void generatePaths() { base.generatePaths(); List <List <int> > points = new List <List <int> > { new List <int>(), //Actuals new List <int>() //Futurs }; //Choose starting point and initialize it points[0].Add(rand.Next(cases.Count())); cases[points[0][0]].State = ARX.State.Point; //Search for new point until list present is empty while (restEmptyState()) { ARX.Shuffle(rand, points[0]); foreach (int currentActive in points[0]) { //Determine in which direction the labyrinth is expandable List <ARX.Direction> futurDirection = someRandAdjacent(currentActive); foreach (ARX.Direction eachDirection in futurDirection) { //Expand the labyrinth to the up if (eachDirection == ARX.Direction.Up && !points[1].Contains(Upper(currentActive).Coord)) { if (Upper(currentActive).State == ARX.State.Right) { Upper(currentActive).State = ARX.State.Cross; } else { Upper(currentActive).State = ARX.State.Down; } points[1].Add(Upper(currentActive).Coord); } //Expand the labyrinth to the right else if (eachDirection == ARX.Direction.Right && !points[1].Contains(Righter(currentActive).Coord)) { if (Self(currentActive).State == ARX.State.Down) { Self(currentActive).State = ARX.State.Cross; } else { Self(currentActive).State = ARX.State.Right; } if (Righter(currentActive).State == ARX.State.Void) { Righter(currentActive).State = ARX.State.Point; } points[1].Add(Righter(currentActive).Coord); } //Expand the labyrinth to the down else if (eachDirection == ARX.Direction.Down && !points[1].Contains(Lower(currentActive).Coord)) { if (Self(currentActive).State == ARX.State.Right) { Self(currentActive).State = ARX.State.Cross; } else { Self(currentActive).State = ARX.State.Down; } if (Lower(currentActive).State == ARX.State.Void) { Lower(currentActive).State = ARX.State.Point; } points[1].Add(Lower(currentActive).Coord); } //Expand the labyrinth to the left else if (eachDirection == ARX.Direction.Left && !points[1].Contains(Lefter(currentActive).Coord)) { if (Lefter(currentActive).State == ARX.State.Down) { Lefter(currentActive).State = ARX.State.Cross; } else { Lefter(currentActive).State = ARX.State.Right; } points[1].Add(Lefter(currentActive).Coord); } } } points[0] = new List <int>(points[1]); points[1].Clear(); } for (int eachTry = 0; eachTry <= 100 && !pathsFinished(); eachTry++) { if (eachTry == 100) { generatePaths(); } } }
private void generateZones(int nbZones) { double ratio = Math.Sqrt(((width * height) / nbZones) / Math.PI); List <List <List <int> > > zonesPoints = new List <List <List <int> > >(); //Generate colors order ARX.Shuffle(rand, colorValues); //Generate starting points for each zones for (int eachZone = 0; eachZone < nbZones; eachZone++) { //Generate unique and separeted points in map int newCoord; do { newCoord = rand.Next(0, width * height); }while (inZoneRadius(ratio, zonesPoints, newCoord)); //Create zone's list zonesPoints.Add(new List <List <int> >()); //Create storage inside each zones zonesPoints[eachZone].Add(new List <int>()); //Actuals zonesPoints[eachZone].Add(new List <int>()); //Futurs zonesPoints[eachZone][0].Add(newCoord); //Generate zones id and colors cases[newCoord].Zone = eachZone; cases[newCoord].ZoneColor = Color.FromArgb(int.Parse($"FF{colorValues[eachZone % colorValues.Count]}", System.Globalization.NumberStyles.HexNumber)); } //Build zones on the map while (restEmptyZone()) { //Update each zones foreach (List <List <int> > eachZone in zonesPoints) { //Advance each points foreach (int eachPoint in eachZone[0]) { if (CanGoUp(eachPoint) && Upper(eachPoint).Zone == -1) { Upper(eachPoint).Zone = Self(eachPoint).Zone; //Get actual case color orders Upper(eachPoint).ZoneColor = Self(eachPoint).ZoneColor; eachZone[1].Add(Upper(eachPoint).Coord); } if (CanGoRight(eachPoint) && Righter(eachPoint).Zone == -1) { Righter(eachPoint).Zone = Self(eachPoint).Zone; //Get actual case color orders Righter(eachPoint).ZoneColor = Self(eachPoint).ZoneColor; eachZone[1].Add(Righter(eachPoint).Coord); } if (CanGoDown(eachPoint) && Lower(eachPoint).Zone == -1) { Lower(eachPoint).Zone = Self(eachPoint).Zone; //Get actual case color orders Lower(eachPoint).ZoneColor = Self(eachPoint).ZoneColor; eachZone[1].Add(Lower(eachPoint).Coord); } if (CanGoLeft(eachPoint) && Lefter(eachPoint).Zone == -1) { Lefter(eachPoint).Zone = Self(eachPoint).Zone; //Get actual case color orders Lefter(eachPoint).ZoneColor = Self(eachPoint).ZoneColor; eachZone[1].Add(Lefter(eachPoint).Coord); } } //Pass futurs points in actual points eachZone[0] = new List <int>(eachZone[1]); eachZone[1].Clear(); } } }