Esempio n. 1
0
 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);
 }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }