public void CombineRoad(PuzzleRoad puzzleRoad) { foreach (var spCon in puzzleRoad.SpecialConditions) { var knownSpCon = this.SpecialConditions.FirstOrDefault(s => s.Condition == spCon.Condition); if (knownSpCon != null) { knownSpCon.Amount += spCon.Amount; } else { this.SpecialConditions.Add(spCon); } } var roadHasUpdated = false; if (this.EndPosition == puzzleRoad.EndPosition + 2) { this.EndPosition = puzzleRoad.StartPosition; roadHasUpdated = true; } else if (this.StartPosition == puzzleRoad.EndPosition - 2) { this.EndPosition = puzzleRoad.EndPosition; roadHasUpdated = true; } else if (this.StartPosition == puzzleRoad.StartPosition + 2) { this.EndPosition = puzzleRoad.EndPosition; roadHasUpdated = true; } else if (this.StartPosition == puzzleRoad.StartPosition - 2) { this.EndPosition = puzzleRoad.EndPosition; roadHasUpdated = true; } if (this.EndOrientation == Orientation.Bottom && puzzleRoad.EndOrientation == Orientation.Top) { this.EndOrientation = puzzleRoad.StartOrientation; roadHasUpdated = true; } else if (this.EndOrientation == Orientation.Bottom && puzzleRoad.StartOrientation == Orientation.Top) { this.EndOrientation = puzzleRoad.EndOrientation; roadHasUpdated = true; } if (!roadHasUpdated) //Road is NOT updated! We need to review our method! { } this.EndPuzzleIndex = puzzleRoad.StartPuzzleIndex; this.PuzzleIndexArray.Add(puzzleRoad.StartPuzzleIndex); }
public bool CheckForRoundabout(PuzzleRoad road, PuzzleRoad relevantRoad) { if (road.StartsAndEndsAtSameOrientation && !road.EndPuzzleIndex.HasValue && relevantRoad.StartsAndEndsAtSameOrientation && !relevantRoad.EndPuzzleIndex.HasValue) { OpenPuzzleRoads.Remove(road); OpenPuzzleRoads.Remove(relevantRoad); return(true); } return(false); }
public PuzzleRoad CreatePuzzleRoad(Road road, int startPuzzleIndex) { //int? endPuzzleIndex; var newPuzzleRoad = new PuzzleRoad(startPuzzleIndex, road); var isEndingRoad = IsEndingRoad(ref newPuzzleRoad, null); if (isEndingRoad) { DefinitivePuzzleRoads.Add(newPuzzleRoad); } else { OpenPuzzleRoads.Add(newPuzzleRoad); } return(newPuzzleRoad); }
public void ChangePuzzleRoadListsBasedOnEndings(PuzzleRoad road, PuzzleRoad relevantRoad) { var amountOfOpenRoadEnds = AmountOfOpenRoadEnds(relevantRoad); if (amountOfOpenRoadEnds == 2) { //The relevantroad is still open, we need to further connect roads to the road object. OpenPuzzleRoads.Remove(relevantRoad); } else if (amountOfOpenRoadEnds == 1) { //We connected 2 roads which makes 1 definitive road. OpenPuzzleRoads.Remove(road); DefinitivePuzzleRoads.Add(road); OpenPuzzleRoads.Remove(relevantRoad); } else if (amountOfOpenRoadEnds == 0) { //This shouldn't happen in practice. OpenPuzzleRoads.Remove(relevantRoad); } }
public PuzzleRoad CreatePuzzleRoad(Road road, int startPuzzleIndex) { var newPuzzleRoad = new PuzzleRoad(startPuzzleIndex, road); var amountOfOpenRoadEnds = AmountOfOpenRoadEnds(newPuzzleRoad); if (amountOfOpenRoadEnds == 0) { newPuzzleRoad.EndPuzzleIndex = newPuzzleRoad.StartPuzzleIndex; DefinitivePuzzleRoads.Add(newPuzzleRoad); } else { newPuzzleRoad.RoadStartsOrEndsAtPuzzleEdge = amountOfOpenRoadEnds <= 1; OpenPuzzleRoads.Add(newPuzzleRoad); } if (newPuzzleRoad.RoadAttribute != Condition.None) { newPuzzleRoad.SpecialConditions.Add(newPuzzleRoad.RoadAttribute, 1); } return(newPuzzleRoad); }
public bool FindRoadEndingOnCurrentStart(PuzzleRoad road) { var newPuzzleIndex = road.EndPuzzleIndex.HasValue ? road.EndPuzzleIndex.Value : road.StartPuzzleIndex; //var tileString = String.Join(" + ", UsedTileList.OrderBy(s => s.PuzzleIndex).Select(s => s.ToString())); //var test = UsedTileList; //if (tileString == "1 - 1 - 0° + 2 - 2 - 0° + 3 - 3 - 0° + 4 - 7 - 0° + 5 - 4 - 0° + 6 - 5 - 90°") //{ //} var switchStartToEnd = false; if (road.StartsOrEndsAt(1)) { var findRoad = Enumerable.Empty <PuzzleRoad>(); if (road.EndPosition == 1) { findRoad = OpenPuzzleRoads.Where(s => newPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) + 3 && s.StartsOrEndsAt(6)); } if (!findRoad.Any() && road.StartPosition == 1) { findRoad = OpenPuzzleRoads.Where(s => road.StartPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) + 3 && s.StartsOrEndsAt(6)); if (findRoad.Count() == 1) { switchStartToEnd = true; } } if (findRoad.Count() == 1) { var relevantRoad = findRoad.First(); if (!CheckForRoundabout(road, relevantRoad)) { road.CombineRoad(relevantRoad, switchStartToEnd); ChangePuzzleRoadListsBasedOnEndings(road, relevantRoad); } return(true); } } if (road.StartsOrEndsAt(2)) { var findRoad = Enumerable.Empty <PuzzleRoad>(); if (road.EndPosition == 2) { findRoad = OpenPuzzleRoads.Where(s => newPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) + 3 && s.StartsOrEndsAt(5)); } if (!findRoad.Any() && road.StartPosition == 2) { findRoad = OpenPuzzleRoads.Where(s => road.StartPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) + 3 && s.StartsOrEndsAt(5)); if (findRoad.Count() == 1) { switchStartToEnd = true; } } if (findRoad.Count() == 1) { var relevantRoad = findRoad.First(); if (!CheckForRoundabout(road, relevantRoad)) { road.CombineRoad(relevantRoad, switchStartToEnd); ChangePuzzleRoadListsBasedOnEndings(road, relevantRoad); } return(true); } } if (road.StartsOrEndsAt(3)) { var findRoad = Enumerable.Empty <PuzzleRoad>(); if (road.EndPosition == 3 && newPuzzleIndex != 3) // Otherwise puzzle index 3 looks to the right (puzzle index 4) for roads { findRoad = OpenPuzzleRoads.Where(s => newPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) - 1 && s.StartsOrEndsAt(8)); } if (!findRoad.Any() && road.StartPosition == 3 && road.StartPuzzleIndex != 3) { findRoad = OpenPuzzleRoads.Where(s => road.StartPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) - 1 && s.StartsOrEndsAt(8)); if (findRoad.Count() == 1) { switchStartToEnd = true; } } if (findRoad.Count() == 1) { var relevantRoad = findRoad.First(); if (!CheckForRoundabout(road, relevantRoad)) { road.CombineRoad(relevantRoad, switchStartToEnd); ChangePuzzleRoadListsBasedOnEndings(road, relevantRoad); } return(true); } } if (road.StartsOrEndsAt(4)) { var findRoad = Enumerable.Empty <PuzzleRoad>(); if (road.EndPosition == 4 && newPuzzleIndex != 3) // Otherwise puzzle index 3 looks to the right (puzzle index 4) for roads { findRoad = OpenPuzzleRoads.Where(s => newPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) - 1 && s.StartsOrEndsAt(7)); } if (!findRoad.Any() && road.StartPosition == 4 && road.StartPuzzleIndex != 3) { findRoad = OpenPuzzleRoads.Where(s => road.StartPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) - 1 && s.StartsOrEndsAt(7)); if (findRoad.Count() == 1) { switchStartToEnd = true; } } if (findRoad.Count() == 1) { var relevantRoad = findRoad.First(); if (!CheckForRoundabout(road, relevantRoad)) { road.CombineRoad(relevantRoad, switchStartToEnd); ChangePuzzleRoadListsBasedOnEndings(road, relevantRoad); } return(true); } } if (road.StartsOrEndsAt(5)) { var findRoad = Enumerable.Empty <PuzzleRoad>(); if (road.EndPosition == 5) { findRoad = OpenPuzzleRoads.Where(s => newPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) - 3 && s.StartsOrEndsAt(2)); } if (!findRoad.Any() && road.StartPosition == 5) { findRoad = OpenPuzzleRoads.Where(s => road.StartPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) - 3 && s.StartsOrEndsAt(2)); if (findRoad.Count() == 1) { switchStartToEnd = true; } } if (findRoad.Count() == 1) { var relevantRoad = findRoad.First(); if (!CheckForRoundabout(road, relevantRoad)) { road.CombineRoad(relevantRoad, switchStartToEnd); ChangePuzzleRoadListsBasedOnEndings(road, relevantRoad); } return(true); } } if (road.StartsOrEndsAt(6)) { var findRoad = Enumerable.Empty <PuzzleRoad>(); if (road.EndPosition == 6) { findRoad = OpenPuzzleRoads.Where(s => newPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) - 3 && s.StartsOrEndsAt(1)); } if (!findRoad.Any() && road.StartPosition == 6) { findRoad = OpenPuzzleRoads.Where(s => road.StartPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) - 3 && s.StartsOrEndsAt(1)); if (findRoad.Count() == 1) { switchStartToEnd = true; } } if (findRoad.Count() == 1) { var relevantRoad = findRoad.First(); if (!CheckForRoundabout(road, relevantRoad)) { road.CombineRoad(relevantRoad, switchStartToEnd); ChangePuzzleRoadListsBasedOnEndings(road, relevantRoad); } return(true); } } if (road.StartsOrEndsAt(7)) { var findRoad = Enumerable.Empty <PuzzleRoad>(); if (road.EndPosition == 7 && newPuzzleIndex != 4) // Otherwise puzzle index 4 looks to the left (puzzle index 3) for roads { findRoad = OpenPuzzleRoads.Where(s => newPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) + 1 && s.StartsOrEndsAt(4)); } if (!findRoad.Any() && road.StartPosition == 7 && road.StartPuzzleIndex != 4) { findRoad = OpenPuzzleRoads.Where(s => road.StartPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) + 1 && s.StartsOrEndsAt(4)); if (findRoad.Count() == 1) { switchStartToEnd = true; } } if (findRoad.Count() == 1) { var relevantRoad = findRoad.First(); if (!CheckForRoundabout(road, relevantRoad)) { road.CombineRoad(relevantRoad, switchStartToEnd); ChangePuzzleRoadListsBasedOnEndings(road, relevantRoad); } return(true); } } if (road.StartsOrEndsAt(8)) { var findRoad = Enumerable.Empty <PuzzleRoad>(); if (road.EndPosition == 8 && newPuzzleIndex != 4) // Otherwise puzzle index 4 looks to the left (puzzle index 3) for roads { findRoad = OpenPuzzleRoads.Where(s => newPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) + 1 && s.StartsOrEndsAt(3)); } if (!findRoad.Any() && road.StartPosition == 8 && road.StartPuzzleIndex != 4) { findRoad = OpenPuzzleRoads.Where(s => road.StartPuzzleIndex == (s.EndPuzzleIndex.HasValue ? s.EndPuzzleIndex.Value : s.StartPuzzleIndex) + 1 && s.StartsOrEndsAt(3)); if (findRoad.Count() == 1) { switchStartToEnd = true; } } if (findRoad.Count() == 1) { var relevantRoad = findRoad.First(); if (!CheckForRoundabout(road, relevantRoad)) { road.CombineRoad(relevantRoad, switchStartToEnd); ChangePuzzleRoadListsBasedOnEndings(road, relevantRoad); } return(true); } } //Het gaat hier HELEMAAL niet goed. Er is geen weg gevonden!? return(false); }
public int AmountOfOpenRoadEnds(PuzzleRoad puzzleRoad) { int amount = 0; var usingPuzzleIndex = puzzleRoad.StartPuzzleIndex; if (puzzleRoad.DefinitiveEndingRoad(usingPuzzleIndex)) { return(0); } switch (usingPuzzleIndex) { case 1: if (!Initiator.SubmittedPuzzleTilesIndices.Contains(2) && !Initiator.SubmittedPuzzleTilesIndices.Contains(4)) { return(0); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(4)) { if (puzzleRoad.StartsAt(Orientation.Bottom)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Bottom); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(2)) { if (puzzleRoad.StartsAt(Orientation.Right)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Right); } break; case 2: if (!Initiator.SubmittedPuzzleTilesIndices.Contains(1) && !Initiator.SubmittedPuzzleTilesIndices.Contains(3) && !Initiator.SubmittedPuzzleTilesIndices.Contains(5)) { return(0); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(1)) { if (puzzleRoad.StartsAt(Orientation.Left)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Left); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(3)) { if (puzzleRoad.StartsAt(Orientation.Right)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Right); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(5)) { if (puzzleRoad.StartsAt(Orientation.Bottom)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Bottom); } break; case 3: if (!Initiator.SubmittedPuzzleTilesIndices.Contains(2) && !Initiator.SubmittedPuzzleTilesIndices.Contains(6)) { return(0); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(2)) { if (puzzleRoad.StartsAt(Orientation.Left)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Left); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(6)) { if (puzzleRoad.StartsAt(Orientation.Bottom)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Bottom); } break; case 4: if (!Initiator.SubmittedPuzzleTilesIndices.Contains(1) && !Initiator.SubmittedPuzzleTilesIndices.Contains(5)) { return(0); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(1)) { if (puzzleRoad.StartsAt(Orientation.Top)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Top); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(5)) { if (puzzleRoad.StartsAt(Orientation.Right)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Right); } break; case 5: if (!Initiator.SubmittedPuzzleTilesIndices.Contains(4) && !Initiator.SubmittedPuzzleTilesIndices.Contains(6) && !Initiator.SubmittedPuzzleTilesIndices.Contains(2)) { return(0); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(4)) { if (puzzleRoad.StartsAt(Orientation.Left)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Left); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(6)) { if (puzzleRoad.StartsAt(Orientation.Right)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Right); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(2)) { if (puzzleRoad.StartsAt(Orientation.Top)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Top); } break; case 6: if (!Initiator.SubmittedPuzzleTilesIndices.Contains(3) && !Initiator.SubmittedPuzzleTilesIndices.Contains(5)) { return(0); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(3)) { if (puzzleRoad.StartsAt(Orientation.Top)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Top); } if (Initiator.SubmittedPuzzleTilesIndices.Contains(5)) { if (puzzleRoad.StartsAt(Orientation.Left)) { puzzleRoad.SwitchStartToEnd(); } amount += puzzleRoad.StartsOrEndsAtAmount(Orientation.Left); } break; } return(amount); }
public bool IsEndingRoad(ref PuzzleRoad puzzleRoad, int?customStartPuzzleIndex) { bool?endingRoad = null; var usingPuzzleIndex = customStartPuzzleIndex.HasValue ? customStartPuzzleIndex.Value : puzzleRoad.StartPuzzleIndex; if (puzzleRoad.DefinitiveEndingRoad(usingPuzzleIndex)) { endingRoad = true; puzzleRoad.EndPuzzleIndex = puzzleRoad.StartPuzzleIndex; return(endingRoad.Value); } switch (usingPuzzleIndex) { case 1: if (!UsedPuzzleTilesIndices.Contains(2) && !UsedPuzzleTilesIndices.Contains(4)) { endingRoad = true; break; } if (UsedPuzzleTilesIndices.Contains(4) && puzzleRoad.StartsOrEndsAt(Orientation.Bottom)) { break; } if (UsedPuzzleTilesIndices.Contains(2) && puzzleRoad.StartsOrEndsAt(Orientation.Right)) { break; } if (!UsedPuzzleTilesIndices.Contains(2)) { if (!puzzleRoad.StartsOrEndsAt(Orientation.Bottom)) { endingRoad = true; break; } } if (!UsedPuzzleTilesIndices.Contains(4)) { if (!puzzleRoad.StartsOrEndsAt(Orientation.Right)) { endingRoad = true; break; } } break; case 2: if (!UsedPuzzleTilesIndices.Contains(1) && !UsedPuzzleTilesIndices.Contains(3) && !UsedPuzzleTilesIndices.Contains(5)) { endingRoad = true; break; } if (!UsedPuzzleTilesIndices.Contains(1)) { if ((puzzleRoad.EndPosition == 0 && puzzleRoad.EndOrientation == Orientation.Left) || (puzzleRoad.EndPosition == 2 && puzzleRoad.EndOrientation == Orientation.Left)) { endingRoad = true; break; } } if (!UsedPuzzleTilesIndices.Contains(3)) { if ((puzzleRoad.EndPosition == 1 && puzzleRoad.EndOrientation == Orientation.Right) || (puzzleRoad.EndPosition == 3 && puzzleRoad.EndOrientation == Orientation.Right)) { endingRoad = true; break; } } if (!UsedPuzzleTilesIndices.Contains(5)) { if ((puzzleRoad.EndPosition == 2 && puzzleRoad.EndOrientation == Orientation.Bottom) || (puzzleRoad.EndPosition == 3 && puzzleRoad.EndOrientation == Orientation.Bottom)) { endingRoad = true; break; } } break; case 3: if (!UsedPuzzleTilesIndices.Contains(2) && !UsedPuzzleTilesIndices.Contains(6)) { endingRoad = true; break; } if (!UsedPuzzleTilesIndices.Contains(2)) { if ((puzzleRoad.EndPosition == 0 && puzzleRoad.EndOrientation == Orientation.Left) || (puzzleRoad.EndPosition == 2 && puzzleRoad.EndOrientation == Orientation.Left)) { endingRoad = true; break; } } if (!UsedPuzzleTilesIndices.Contains(6)) { if ((puzzleRoad.EndPosition == 2 && puzzleRoad.EndOrientation == Orientation.Bottom) || (puzzleRoad.EndPosition == 3 && puzzleRoad.EndOrientation == Orientation.Bottom)) { endingRoad = true; break; } } break; case 4: if (!UsedPuzzleTilesIndices.Contains(1) && !UsedPuzzleTilesIndices.Contains(5)) { endingRoad = true; break; } if (UsedPuzzleTilesIndices.Contains(1) && puzzleRoad.StartsOrEndsAt(Orientation.Top)) { break; } if (UsedPuzzleTilesIndices.Contains(5) && puzzleRoad.StartsOrEndsAt(Orientation.Right)) { break; } if (!UsedPuzzleTilesIndices.Contains(1)) { if (puzzleRoad.StartsOrEndsAt(Orientation.Top)) { endingRoad = true; break; } } if (!UsedPuzzleTilesIndices.Contains(5)) { if (puzzleRoad.StartsOrEndsAt(Orientation.Right)) { endingRoad = true; break; } } break; case 5: if (!UsedPuzzleTilesIndices.Contains(4) && !UsedPuzzleTilesIndices.Contains(6) && !UsedPuzzleTilesIndices.Contains(2)) { endingRoad = true; break; } if (!UsedPuzzleTilesIndices.Contains(4)) { if ((puzzleRoad.EndPosition == 0 && puzzleRoad.EndOrientation == Orientation.Left) || (puzzleRoad.EndPosition == 2 && puzzleRoad.EndOrientation == Orientation.Left)) { endingRoad = true; break; } } if (!UsedPuzzleTilesIndices.Contains(6)) { if ((puzzleRoad.EndPosition == 1 && puzzleRoad.EndOrientation == Orientation.Right) || (puzzleRoad.EndPosition == 3 && puzzleRoad.EndOrientation == Orientation.Right)) { endingRoad = true; break; } } if (!UsedPuzzleTilesIndices.Contains(2)) { if ((puzzleRoad.EndPosition == 0 && puzzleRoad.EndOrientation == Orientation.Top) || (puzzleRoad.EndPosition == 1 && puzzleRoad.EndOrientation == Orientation.Top)) { endingRoad = true; break; } } break; case 6: if (!UsedPuzzleTilesIndices.Contains(3) && !UsedPuzzleTilesIndices.Contains(5)) { endingRoad = true; break; } if (!UsedPuzzleTilesIndices.Contains(3)) { if ((puzzleRoad.EndPosition == 0 && puzzleRoad.EndOrientation == Orientation.Top) || (puzzleRoad.EndPosition == 1 && puzzleRoad.EndOrientation == Orientation.Top)) { endingRoad = true; break; } } if (!UsedPuzzleTilesIndices.Contains(5)) { if ((puzzleRoad.EndPosition == 0 && puzzleRoad.EndOrientation == Orientation.Left) || (puzzleRoad.EndPosition == 2 && puzzleRoad.EndOrientation == Orientation.Left)) { endingRoad = true; break; } } break; } if (endingRoad.HasValue && endingRoad.Value) { puzzleRoad.EndPuzzleIndex = usingPuzzleIndex; } return(endingRoad.HasValue ? endingRoad.Value : false); }
public PuzzleRoad FindRoadEndingOnCurrentStart(PuzzleRoad road) { if (road.StartsOrEndsAt(Orientation.Bottom)) { var findRpad = OpenPuzzleRoads.Where(s => (road.StartPuzzleIndex == s.StartPuzzleIndex - 3 || road.StartPuzzleIndex == s.StartPuzzleIndex + 3) && ((road.EndPosition == s.EndPosition + 2 && s.EndsAt(Orientation.Top)) || (road.EndPosition == s.StartPosition + 2 && s.StartsAt(Orientation.Top)) || (road.StartPosition == s.StartPosition + 2 && s.StartsAt(Orientation.Top)) || (road.StartPosition == s.EndPosition + 2 && s.EndsAt(Orientation.Top)))); if (!findRpad.Any() || findRpad.Count() > 1) { //Dit giet even krek mis. Teveel of te weinig roads! var test = UsedTileList; } else { var relevantRoad = findRpad.First(); if (road.PuzzleIndexArray.Count > 1) { road.CombineRoad(relevantRoad); if (IsEndingRoad(ref road, relevantRoad.StartPuzzleIndex)) { road.EndPuzzleIndex = relevantRoad.StartPuzzleIndex; OpenPuzzleRoads.Remove(road); DefinitivePuzzleRoads.Add(road); } } else { road.CombineRoad(relevantRoad); if (IsEndingRoad(ref road, null)) { road.EndPuzzleIndex = relevantRoad.StartPuzzleIndex; OpenPuzzleRoads.Remove(road); DefinitivePuzzleRoads.Add(road); } OpenPuzzleRoads.Remove(relevantRoad); return(road); } } } if (road.StartsOrEndsAt(Orientation.Top)) { var findRpad = OpenPuzzleRoads.Where(s => (road.StartPuzzleIndex == s.StartPuzzleIndex - 3 || road.StartPuzzleIndex == s.StartPuzzleIndex + 3) && ((road.EndPosition == s.EndPosition - 2 && s.EndsAt(Orientation.Bottom)) || (road.EndPosition == s.StartPosition - 2 && s.StartsAt(Orientation.Bottom)) || (road.StartPosition == s.StartPosition - 2 && s.StartsAt(Orientation.Bottom)) || (road.StartPosition == s.EndPosition - 2 && s.EndsAt(Orientation.Bottom)))); if (!findRpad.Any() || findRpad.Count() > 1) { //Dit giet even krek mis. Teveel of te weinig roads! var test = UsedTileList; } else { var getFirst = findRpad.First(); { road.CombineRoad(getFirst); OpenPuzzleRoads.Remove(road); OpenPuzzleRoads.Remove(getFirst); DefinitivePuzzleRoads.Add(road); return(road); } } } //Het gaat hier HELEMAAL niet goed. Er is geen weg gevonden!? return(null); }