Esempio 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);
                }
            }
        }
Esempio n. 2
0
        private static void UpdateGenePoolFilesUponExtinction()
        {
            Dictionary <string, int> fileNameToModificationDic = new Dictionary <string, int> ();

            // Tabulate the new win loss info for the parent files
            foreach (KeyValuePair <string, GeneData> keyValuePair in teamNameToGeneDataDic)
            {
                string teamName       = keyValuePair.Key;
                string parentFileName = keyValuePair.Value.ParentDNAFilePath;

                int teamPopCount = TeamManager.GetTeamPopulationCount(teamName);
                int modification = teamPopCount - AverageTeamPopulationCount();

                if (fileNameToModificationDic.ContainsKey(parentFileName))
                {
                    // Update
                    fileNameToModificationDic[parentFileName] += modification;
                }
                else
                {
                    // Create new entry
                    int startingParentWinLoss = ParseWinLoss(keyValuePair.Value.ParentDNAFilePath);
                    fileNameToModificationDic.Add(parentFileName, startingParentWinLoss + modification);
                }
            }

            // Move or delete the parent files as appropriate
            foreach (KeyValuePair <string, int> keyValuePair in fileNameToModificationDic)
            {
                string oldFileName  = keyValuePair.Key;
                int    winLossCount = keyValuePair.Value;

                if (winLossCount <= 0)
                {
                    // Delete losers
                    LogUtility.LogInfoFormat(
                        "Removing {0} from gene pool",
                        oldFileName);

                    FileIOManager.Delete(oldFileName);
                    continue;
                }

                // Move winners to new file name
                string newFileName = FileIOManager.GenerateNewDNAFilePath(winLossCount);
                FileIOManager.Move(oldFileName, newFileName);

                LogUtility.LogInfoFormat(
                    "Gene pool file {0} became {1}",
                    oldFileName,
                    newFileName);
            }
        }
Esempio n. 3
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);
        }