Esempio n. 1
0
        public static RoboPlayerStatistic CalcStatistics(IEnumerable <RoboPlayerResult> results)
        {
            RoboPlayerStatistic stats = new RoboPlayerStatistic();

            foreach (RoboPlayerResult result in results)
            {
                switch (result.State)
                {
                case RoboPlayerState.Dead:
                    stats.Died++;
                    break;

                case RoboPlayerState.Finished:
                    stats.RoundsPlayed += result.RoundsPlayed;
                    stats.CardsPlayed  += result.CardsPlayed;
                    stats.Time         += result.Time.Milliseconds;
                    stats.Finished++;
                    break;

                default:
                    stats.Error++;
                    break;
                }
            }
            return(stats);
        }
Esempio n. 2
0
        private static String GetFormattedStatistics(Dictionary <String, Dictionary <String, List <RoboPlayerResult> > > results)
        {
            StringBuilder builder = new StringBuilder();

            Dictionary <String, List <RoboPlayerStatistic> > playerStats = new Dictionary <String, List <RoboPlayerStatistic> >();

            foreach (KeyValuePair <String, Dictionary <String, List <RoboPlayerResult> > > entry in results)
            {
                builder.Append(entry.Key);
                builder.AppendLine();
                builder.Append(GetFormattedStatistics(entry.Value, playerStats));
                builder.AppendLine();
            }

            Dictionary <String, RoboPlayerStatistic> localStats = new Dictionary <String, RoboPlayerStatistic>();

            builder.AppendLine("Player Totals");
            foreach (KeyValuePair <String, List <RoboPlayerStatistic> > entry in playerStats)
            {
                builder.Append(entry.Key);
                builder.Append("; ");
                builder.Append(PrintStatistics(RoboPlayerStatistic.CalcStatistics(entry.Value)));
                builder.AppendLine();
            }

            return(builder.ToString());
        }
Esempio n. 3
0
        public static RoboPlayerStatistic CalcStatistics(IEnumerable <RoboPlayerStatistic> singleStats)
        {
            RoboPlayerStatistic stats = new RoboPlayerStatistic();

            foreach (RoboPlayerStatistic singleStat in singleStats)
            {
                stats.Finished     += singleStat.Finished;
                stats.Died         += singleStat.Died;
                stats.Finished     += singleStat.Error;
                stats.RoundsPlayed += singleStat.RoundsPlayed;
                stats.CardsPlayed  += singleStat.CardsPlayed;
                stats.Time         += singleStat.Time;
            }
            return(stats);
        }
Esempio n. 4
0
        private static String PrintStatistics(RoboPlayerStatistic stat)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(stat.Finished);
            builder.Append("; ");
            builder.Append(stat.RoundsPlayed);
            builder.Append("; ");
            builder.Append(stat.CardsPlayed);
            builder.Append("; ");
            builder.Append(stat.Time);
            builder.Append("; ");
            builder.Append(stat.Finished + stat.Died + stat.Error > 0 ? (double)stat.Finished / (stat.Finished + stat.Died + stat.Error) : 0.0);
            builder.Append("; ");
            builder.Append(stat.Finished > 0 ? stat.RoundsPlayed / stat.Finished : 0.0);
            builder.Append("; ");
            builder.Append(stat.Finished > 0 ? stat.CardsPlayed / stat.Finished : 0.0);
            builder.Append("; ");
            builder.Append(stat.Finished > 0 ? stat.Time / stat.Finished : 0.0);
            builder.Append("; ");

            return(builder.ToString());
        }
Esempio n. 5
0
        private static String GetFormattedStatistics(Dictionary <String, List <RoboPlayerResult> > results, Dictionary <String, List <RoboPlayerStatistic> > playerStats)
        {
            StringBuilder builder = new StringBuilder("Player; #win; #rounds; #cards; #time; øwin; ørounds; øcards; øtime");

            builder.AppendLine();

            Dictionary <String, RoboPlayerStatistic> localStats = new Dictionary <String, RoboPlayerStatistic>();

            foreach (KeyValuePair <String, List <RoboPlayerResult> > entry in results)
            {
                RoboPlayerStatistic playerStat = RoboPlayerStatistic.CalcStatistics(entry.Value);

                // fill player overall stats
                if (!playerStats.ContainsKey(entry.Key))
                {
                    playerStats[entry.Key] = new List <RoboPlayerStatistic>();
                }
                List <RoboPlayerStatistic> playerStatsEntry = playerStats[entry.Key];

                playerStatsEntry.Add(playerStat);

                // current board stat
                localStats.Add(entry.Key, playerStat);

                builder.Append(entry.Key);
                builder.Append("; ");
                builder.Append(PrintStatistics(playerStat));
                builder.AppendLine();
            }
            builder.Append("Board Totals");
            builder.Append("; ");
            builder.Append(PrintStatistics(RoboPlayerStatistic.CalcStatistics(localStats.Values)));
            builder.AppendLine();

            return(builder.ToString());
        }