Example #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);
                }
            }
        }
Example #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);
            }
        }
Example #3
0
        private static int AverageTeamPopulationCount()
        {
            int total = 0;
            int count = 0;

            foreach (string teamName in teamNameToGeneDataDic.Keys)
            {
                total += TeamManager.GetTeamPopulationCount(teamName);
                ++count;
            }

            // Will throw if count == 0
            return(total / count);
        }
Example #4
0
        private static int AverageOtherTeamPopulationCount(string excludedTeam)
        {
            int total = 0;
            int count = 0;

            foreach (string teamName in teamNameToGeneDataDic.Keys)
            {
                if (CommonHelperMethods.StringsAreEqual(teamName, excludedTeam))
                {
                    continue;
                }

                total += TeamManager.GetTeamPopulationCount(teamName);
                ++count;
            }

            // Will throw if count == 0
            return(total / count);
        }