Exemplo n.º 1
0
        public void PlayGame(BHTeam home, BHTeam away, GameStat gameStat)
        {
            var tied = true;

            while (tied)
            {
                int score = 0;
                foreach (var player in home.Players)
                {
                    score += ApplyGauss(player.PPG);
                    score -= ApplyGauss(player.Steals);
                    score -= ApplyGauss(player.Rebounds);
                }
                gameStat.HomeScore = score;

                score = 0;
                foreach (var player in away.Players)
                {
                    score += ApplyGauss(player.PPG);
                    score -= ApplyGauss(player.Steals);
                    score -= ApplyGauss(player.Rebounds);
                }
                gameStat.AwayScore = score;
                if (gameStat.HomeScore > gameStat.AwayScore)
                {
                    HomeWins++;
                    tied = false;
                }
                if (gameStat.HomeScore < gameStat.AwayScore)
                {
                    AwayWins++;
                    tied = false;
                }
            }
        }
Exemplo n.º 2
0
        public Series(BHTeam home, BHTeam away, int?num)
        {
            GamesPlayed  = 0;
            HomeWins     = 0;
            AwayWins     = 0;
            HomeTeam     = home;
            AwayTeam     = away;
            SeriesResult = new List <GameStat>();

            if (num == null)
            {
                var gameStat = new GameStat();
                while ((HomeWins == 0 || AwayWins == 0 || GamesPlayed < 3) && GamesPlayed < 100000)
                {
                    PlayGame(HomeTeam, AwayTeam, gameStat);
                    GamesPlayed++;
                    gameStat.GameNum = GamesPlayed;
                }
                SeriesResult.Add(gameStat);
            }
            else
            {
                while (Math.Max(HomeWins, AwayWins) <= num / 2)
                {
                    var gameStat = new GameStat();
                    PlayGame(HomeTeam, AwayTeam, gameStat);
                    GamesPlayed++;
                    gameStat.GameNum = GamesPlayed;
                    SeriesResult.Add(gameStat);
                }
            }

            Winner = null;
            if (HomeWins > AwayWins)
            {
                Winner = home;
            }
            if (HomeWins < AwayWins)
            {
                Winner = away;
            }
        }