private double GetTeamWinPercentage(Team team, Dictionary<Guid, WinLossRecord> winLossRecords)
        {
            // Option 1: Total wins/losses, giving players who have played more a higher weight in the rating
            //			var record = new WinLossRecord();
            //			foreach (var player in team.Members)
            //			{
            //				WinLossRecord winLossRecord;
            //				if (winLossRecords.TryGetValue(player.Id, out winLossRecord))
            //				{
            //					record.Wins += winLossRecord.Wins;
            //					record.Losses += winLossRecord.Losses;
            //					record.Ties += winLossRecord.Ties;
            //				}
            //			}
            //			return record.WinPercentage;

            // Option 2: Average win percentage, equally weighted
            double winPercentage = 0.0;
            foreach (var player in team.Members)
            {
                WinLossRecord winLossRecord;
                if (winLossRecords.TryGetValue(player.Id, out winLossRecord))
                {
                    winPercentage += winLossRecord.WinPercentage;
                }
                else
                {
                    winPercentage += 0.5;
                }
            }

            return winPercentage/team.Members.Count;
        }
Ejemplo n.º 2
0
        public ProposedMatchup[] GetMatchups( Game game, User[] users )
        {
            if ( users.Length < 2 )
            {
                throw new ArgumentException( "At least two players are required" );
            }

            var team1 = new Team();
            var team2 = new Team();

            for ( int i = 0; i < users.Length; i++ )
            {
                if ( i % 2 == 0 )
                {
                    team1.Members.Add( users[i] );
                }
                else
                {
                    team2.Members.Add( users[i] );
                }
            }

            return new ProposedMatchup[]
            {
                new ProposedMatchup( game, team1, team2, winRatioRange.Next() ),
                new ProposedMatchup( game, team1, team2, winRatioRange.Next() ),
                new ProposedMatchup( game, team1, team2, winRatioRange.Next() ),
            };
        }
Ejemplo n.º 3
0
        public ProposedMatchup( Game game, Team team1, Team team2, double team1WinRatio )
        {
            if ( team1WinRatio < 0.0 || team1WinRatio > 1.0 )
            {
                throw new ArgumentException( "Win ratio must be between 0.0 and 1.0" );
            }

            Team1PredictedWinRatio = team1WinRatio;
            Team2PredictedWinRatio = 1.0 - team1WinRatio;

            Game = game;
            Team1 = team1;
            Team2 = team2;
        }
Ejemplo n.º 4
0
        private void CreateMatchHistoryFor( Game game )
        {
            var players = database.GetPlayersForGame( game.Id );

            if ( players.Length < 2 )
            {
                return;
            }

            var selectionPoolSizeRange = new Range<int>( 2, players.Length );

            for ( int i = 0; i < MatchesPerGame; i++ )
            {
                var selectionPoolSize = selectionPoolSizeRange.Next();
                var team1 = new Team();
                var team2 = new Team();

                for ( int j = 0; j < selectionPoolSize; j++ )
                {
                    if ( j.IsEven() )
                    {
                        team1.Members.Add( players[j] );
                    }
                    else
                    {
                        team2.Members.Add( players[j] );
                    }
                }

                var team1Score = ScoreRange.Next();
                var team2Score = ScoreRange.Next();

                var result = new MatchupResult
                {
                    GameId = game.Id,
                    Team1UserIds = team1.Members.Select( user => user.Id ).ToArray(),
                    Team2UserIds = team2.Members.Select( user => user.Id ).ToArray(),
                    Timestamp = DateTime.Now - MatchHistoryLength.Next(),
                    Winner = team1Score.GetWinner(team2Score)
                };

                if ( 0.5.NextBool() )
                {
                    result.Team1Score = team1Score;
                    result.Team2Score = team2Score;
                }

                if ( 0.2.NextBool() )
                {
                    result.Comment = "This is a sample comment";
                }

                result.MapId = GetRandomMap(game).Id;

                database.SaveMatchupResult(result);
            }
        }