Esempio n. 1
0
    /// <summary>
    /// Generiert ein Array, aus Elementen die jeweils aus 'chars' unterschiedlichen Zeichen bestehen, mit jeweils 'places' Stellen.
    /// Das Array beinhaltet alle möglichen Verknüpfungsmöglichkeiten, die durch Permutation ermittelt werden.
    /// Das Ergebnis wird in der als Referenz übergebenen ArrayList 'output' gespeichert.
    /// </summary>
    /// <param name="days">Count of how many days the player would have time to build</param>
    /// <param name="projects">List of the available projects</param>
    /// <param name="output">List in which all the buildpathes will be stored</param>
    /// <param name="allPoints">List in which all the points of each buildpath will be stored</param>
    /// <param name="game">Game holds all the values to provide a environment where project can be build</param>
    /// <param name="outputPart" >Internally parameter to pass on the information during the recursiv progress</param>
    private void GetPermutationPerRef(int days, List<BaseProject> projects, List<string> output, List<int> allPoints, GameStats game, LinkedList<Day> linkedDays, string outputPart = "")
    {
        if (days == 0)
        {
            // If all the days are through,
            // the buildpath is added to a List of buildpathes
            // and the score of that buildpath is added to the scorelist
            AddDaytoList(days, game, linkedDays);

            allPoints.Add(game.points);
            output.Add(outputPart);
            dayInfo.Add(linkedDays);
        }
        else
        {
            if (projects.Count > 0) // there are projects which can be build
            {
                // for each new baseproject there is a complete new buildpath
                foreach (BaseProject p in projects)
                {
                    // because the days are getting counted down every new buildpath starts with the maximum count of days
                    // the game environment gets reset as do the linkedlist of days
                    if (days == maxDays)
                    {
                        game.Reset();
                        linkedDays.Clear();
                    }
                    // check if the day already exists
                    LinkedListNode<Day> currentDay = FindDay(days, linkedDays);

                    BrandNewDay(days, currentDay, game, linkedDays);

                    // the barriers prevent not promising buildpathes from being furhter pursued
                    // so that the numbers of possible buildpathes dont get out of hand
                    if (days == (maxDays - barrierer0) && game.points <= pointsBarrierer0)
                    {
                        // end of tail recursion
                    }
                    else if (days == (maxDays - barrierer1) && game.points <= pointsBarrierer1)
                    {
                        // end of tail recursion
                    }
                    else if (days == (maxDays - barrierer2) && game.points <= pointsBarrierer2)
                    {
                        // end of tail recursion
                    }
                    else if (days == (maxDays - barrierer3) && game.points <= pointsBarrierer3)
                    {
                        // end of tail recursion
                    }
                    else
                    {
                        // construct the current project
                        game.BuyProject(p);

                        // move on to the next day
                        game.nextDay();

                        // find all the projects the player could buy the next day
                        projects = game.GetBuyAbleBaseProjects();

                        // tail recursion
                        GetPermutationPerRef(days - 1, projects, output, allPoints, game, linkedDays, outputPart + p.projectName + " ");
                    }
                }
            }
            else // there are no projects which can be build
            {
                if (days == maxDays)
                {
                    game.Reset();
                    linkedDays.Clear();
                }

                if (days == (maxDays - barrierer0) && game.points <= pointsBarrierer0)
                {
                    // ende
                }
                else if (days == (maxDays - barrierer1) && game.points <= pointsBarrierer1)
                {
                    // ende
                }
                else if (days == (maxDays - barrierer2) && game.points <= pointsBarrierer2)
                {
                    // ende
                }
                else if (days == (maxDays - barrierer3) && game.points <= pointsBarrierer3)
                {
                    // ende
                }
                else
                {
                    // check if the day already exists
                    LinkedListNode<Day> currentDay = FindDay(days, linkedDays);
                    BrandNewDay(days, currentDay, game, linkedDays);

                    // dont buy or upgrade any project

                    game.nextDay();

                    projects = game.GetBuyAbleBaseProjects();

                    GetPermutationPerRef(days - 1,
                        projects,
                        output,
                        allPoints,
                        game,
                        linkedDays,
                        outputPart + "empty ");
                }
            }
        }
    }