Exemplo n.º 1
0
        private static void AddSurvivorsToGenePool()
        {
            foreach (KeyValuePair <string, GeneData> keyValuePair in teamNameToGeneDataDic)
            {
                string   teamName = keyValuePair.Key;
                GeneData geneData = keyValuePair.Value;

                int teamPopCount = TeamManager.GetTeamPopulationCount(teamName);
                int winCount     = 1 + teamPopCount - AverageTeamPopulationCount();

                if (winCount <= 0)
                {
                    // Losers don't get laid
                    continue;
                }

                // Have to place a cap on number of files, otherwise this would flood the machine
                if (FileIOManager.GetFileNames().Count < GenePoolDirectoryFileLimit)
                {
                    LogUtility.LogInfoFormat(
                        "{0} writes DNA to disk",
                        teamName);

                    geneData.DNA.WriteToDisk(FileIOManager.GenerateNewDNAFilePath(winCount));
                }
                else
                {
                    LogUtility.LogInfoFormat(
                        "Gene Pool has reached max size of {0} files",
                        GenePoolDirectoryFileLimit);
                }
            }
        }
Exemplo n.º 2
0
        private static IList <string> GetNotTakenParentFiles()
        {
            List <string> fileNameList = FileIOManager.GetFileNames();

            // Ensure no repeats
            List <string> candidates = new List <string>();

            foreach (string fileName in fileNameList)
            {
                if (!CommonHelperMethods.StringContainsSubString(fileName, FileIOManager.DNAFileExtension))
                {
                    // Ingnore any other files that might get in there
                    continue;
                }

                if (teamNameToGeneDataDic.Count > 0)
                {
                    foreach (GeneData data in teamNameToGeneDataDic.Values)
                    {
                        if (CommonHelperMethods.StringsAreEqual(data.ParentDNAFilePath, fileName))
                        {
                            continue;
                        }

                        candidates.Add(fileName);
                    }
                }
                else
                {
                    candidates.Add(fileName);
                }
            }

            if (candidates.Count == 0)
            {
                string defaultDNAFilePath = FileIOManager.GenerateNewDNAFilePath(1);
                candidates.Add(defaultDNAFilePath);
            }

            return(candidates);
        }