public ProposedMatchup[] GetMatchups(Game game, User[] players)
        {
            var matchups = new List<ProposedMatchup>();
            var proposersMatchups = new ConcurrentQueue<ProposedMatchup[]>();
            Parallel.ForEach(proposers, proposer => proposersMatchups.Enqueue(proposer.GetMatchups(game, players).OrderBy(GetMatchupIdentifier).ToArray()));

            var proposersMatchupsArray = proposersMatchups.ToArray();
            int possibleMatchups =  0;
            for (int i = 0; i < proposersMatchupsArray.Length - 1; i++)
            {
                possibleMatchups = proposersMatchupsArray[i].Length;
                if(proposersMatchupsArray[i].Length != proposersMatchupsArray[i+1].Length)
                {
                    throw new Exception("Multiple Proposer Matchups do not Match");
                }
            }

            for (int i = 0; i < possibleMatchups; i++)
            {
                double team1Value = 0d;
                double team2Value = 0d;
                for (int j = 0; j < proposersMatchupsArray.Length; j++)
                {
                    team1Value += weights[j] * proposersMatchupsArray[j][i].Team1PredictedWinRatio;
                    team2Value += weights[j] * proposersMatchupsArray[j][i].Team2PredictedWinRatio;
                }

                var team1 = proposersMatchupsArray[0][i].Team1;
                var team2 = proposersMatchupsArray[0][i].Team2;
                matchups.Add(new ProposedMatchup(game, team1, team2, team1Value / (team1Value + team2Value)));

            }

            return matchups.ToArray();
        }
        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() ),
            };
        }
Beispiel #3
0
        public Dictionary<Guid, double> CalculateAverageRatings(Game game, IEnumerable<User> players)
        {
            //var cutoff = DateTime.Now - settings.PlayerRatingExpiryTime;
            var averageRatings = new Dictionary<Guid, double>();
            foreach (var player in players)
            {
                var average = CalculateAverageRating(database.GetMostRecentPlayerRatings(game.Id, player.Id), DateTime.Now);

                averageRatings.Add(player.Id, average.HasValue ? average.Value : 1.0);
                /*double averageRating = 0.0;
                int ratingsCounted = 0;
                var ratings = database.GetMostRecentPlayerRatings(game.Id, player.Id);
                foreach (var rating in ratings)
                {
                    if (!rating.Rating.HasValue || rating.Timestamp < cutoff) continue;

                    ratingsCounted++;
                    averageRating += rating.Rating.Value;
                }

                if (ratingsCounted > 0)
                {
                    averageRatings[player.Id] = averageRating / ratingsCounted;
                }*/
            }
            return averageRatings;
        }
Beispiel #4
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;
        }
Beispiel #5
0
        protected GameModule( IDatabase database )
            : base("{gameKey}/")
        {
            Before.AddItemToStartOfPipeline( context =>
            {
                var gameKey = (string)context.Parameters.gameKey;

                game = database.GetGameByKey( gameKey );

                context.ViewBag[ViewBagKeys.CurrentGame] = game;

                return null;
            } );
        }
        public ProposedMatchup[] GetMatchups( Game game, User[] players )
        {
            Dictionary<Guid, Dictionary<Guid, Link>> links = GetLinks( database.GetMatchupResultsByGame( game.Id ), players );
            List<Tuple<Team, Team>> teams = TeamGenerator.GenerateTeams( players );

            var matchups = new List<ProposedMatchup>();

            foreach ( var teamPair in teams )
            {
                var team1Probability = CalculateTeamLinkAverage(links, teamPair.Item1);
                var team2Probability = CalculateTeamLinkAverage(links, teamPair.Item2);
                matchups.Add( new ProposedMatchup( game, teamPair.Item1, teamPair.Item2, team1Probability/(team1Probability + team2Probability) ) );
            }

            return matchups.ToArray();
        }
        public ProposedMatchup[] GetMatchups(Game game, User[] players)
        {
            var averageRatings = ratingsHelper.CalculateAverageRatings(game, players);

            var teams = TeamGenerator.GenerateTeams(players);
            var matchups = new List<ProposedMatchup>();

            foreach (var teamPair in teams)
            {
            var team1 = teamPair.Item1;
                var team2 = teamPair.Item2;
                var team1Ratings = GetTeamRating(team1, averageRatings);
                var team2Ratings = GetTeamRating(team2, averageRatings);
                matchups.Add(new ProposedMatchup(game, team1, team2, team1Ratings / (team1Ratings + team2Ratings)));
            }

            return matchups.ToArray();
        }
        public ProposedMatchup[] GetMatchups(Game game, User[] players)
        {
            var winLossRecords = new Dictionary<Guid, WinLossRecord>();
            foreach (var player in players)
            {
                winLossRecords[player.Id] = database.GetWinLossRecord(game.Id, player.Id);
            }

            var teams = TeamGenerator.GenerateTeams(players);
            var matchups = new List<ProposedMatchup>();
            foreach (var teamPair in teams)
            {
                var team1 = teamPair.Item1;
                var team2 = teamPair.Item2;
                var team1WinPercentage = GetTeamWinPercentage(team1, winLossRecords);
                var team2WinPercentage = GetTeamWinPercentage(team2, winLossRecords);
                matchups.Add(new ProposedMatchup(game, team1, team2, team1WinPercentage / (team1WinPercentage + team2WinPercentage)));
            }

            return matchups.ToArray();
        }
 public SelectGameViewModel( Game[] games )
 {
     Games = new List<Game>(games);
 }
 private Map GetRandomMap(Game game)
 {
     return Maps[random.Next(0, Maps.Length)];
 }
        private void CreateRatingsFor( Game game )
        {
            var players = database.GetPlayersForGame( game.Id );

            foreach ( var ratingPlayer in players )
            {
                foreach ( var ratedPlayer in players )
                {
                    var numberOfRatings = RatingsPerPlayer.Next();

                    for ( int i = 0; i < numberOfRatings; i++ )
                    {
                        var rating = new PlayerRating();
                        rating.GameId = game.Id;
                        rating.PlayerId = ratedPlayer.Id;
                        rating.RatedByPlayerId = ratingPlayer.Id;
                        rating.Timestamp = DateTime.Now - PlayerRatingHistoryLength.Next();

                        if ( .8.NextBool() )
                        {
                            rating.Rating = RatingRange.Next();
                        }

                        database.AddPlayerRating( rating );
                    }
                }
            }
        }
        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);
            }
        }
        private void CreateGames()
        {
            foreach ( var gameName in GameNames )
            {
                var game = new Game() {Name = gameName, Key = CreateGameKeyFromName(gameName), MapIds = new List<Guid>(from m in Maps select m.Id)};

                database.AddGame(game);
            }
        }
Beispiel #14
0
 public void AddGame( Game game )
 {
     database
         .GetCollection<Game>( Collections.Games )
         .Insert( game );
 }
Beispiel #15
0
        private void CreateSampleGame()
        {
            var game = new Game()
            {
                Key = "l4d2",
                Name = "Left 4 Dead 2",
            };

            AddGame(game);
        }
Beispiel #16
0
 public void AddGame( Game game )
 {
     this.games.Add(game);
 }
Beispiel #17
0
 public ProposedMatchup( Game game, IEnumerable<User> team1Players, IEnumerable<User> team2Players, double team1WinRatio )
     : this(game, new Team(team1Players), new Team(team2Players), team1WinRatio)
 {
 }