コード例 #1
0
        public MatchupResultViewModel( MatchupResult result, IdentityMap<User> userMap, Map gameMap )
        {
            Timestamp = result.Timestamp;
            HowRecent = ( DateTime.Now - Timestamp ).ToShortString() + " ago";
            Comment = result.Comment;
            Team1Score = result.Team1Score;
            Team2Score = result.Team2Score;
            Winner = result.Winner;
            this.Map = gameMap;

            Team1PlayerNames = result
                .Team1UserIds
                .Select( userMap.Lookup )
                .Select(user => user.Name)
                .ToList();

            Team2PlayerNames = result
                .Team2UserIds
                .Select( userMap.Lookup )
                .Select(user => user.Name)
                .ToList();
        }
コード例 #2
0
        private Dictionary<Guid, Dictionary<Guid, Link>> GetLinks( MatchupResult[] PreviousGames, User[] players )
        {
            var result = new Dictionary<Guid, Dictionary<Guid, Link>>();
            var playerDictionary = new Dictionary<Guid, User>();
            foreach ( User user in players )
            {
                result.Add( user.Id, new Dictionary<Guid, Link>() );
                playerDictionary.Add( user.Id, user );
            }

            foreach ( MatchupResult matchup in PreviousGames )
            {
                foreach ( Guid id in matchup.Team1UserIds )
                {
                    if ( !playerDictionary.Keys.Contains( id ) )
                    {
                        continue;
                    }
                    foreach ( Guid otherId in matchup.Team1UserIds )
                    {
                        if ( !playerDictionary.Keys.Contains( otherId ) || id == otherId || result[id] == null )
                        {
                            continue;
                        }
                        if ( !result[id].ContainsKey( otherId ) )
                        {
                            result[id].Add( otherId, new Link( playerDictionary[otherId] ) );
                        }
                        result[id][otherId].AddGame( matchup );
                    }
                }
                foreach ( Guid id in matchup.Team2UserIds )
                {
                    if ( !playerDictionary.Keys.Contains( id ) )
                    {
                        continue;
                    }
                    foreach ( Guid otherId in matchup.Team2UserIds )
                    {
                        if ( !playerDictionary.Keys.Contains( otherId ) || id == otherId || result[id] == null )
                        {
                            continue;
                        }
                        if ( !result[id].ContainsKey( otherId ) )
                        {
                            result[id].Add( otherId, new Link( playerDictionary[otherId] ) );
                        }
                        result[id][otherId].AddGame( matchup );
                    }
                }
            }

            foreach(var player in result.Keys)
            {
                foreach(var otherPlayer in result.Keys)
                {
                    if (player.Equals(otherPlayer) || !result[player].Keys.Contains(otherPlayer))
                        continue;
                    if(result[player][otherPlayer].GetGameCount()>maxLinks)
                    {
                        result[player][otherPlayer].RemoveOldGames(maxLinks);
                    }
                    if (result[player][otherPlayer].GetGameCount() < minLinks)
                    {
                        result[player][otherPlayer].BackfillOldGames(minLinks);
                    }
                }
            }

            return result;
        }
コード例 #3
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);
            }
        }
コード例 #4
0
ファイル: TestDatabase.cs プロジェクト: Breeto/MatchMaker
 public void SaveMatchupResult( MatchupResult result )
 {
     matchupResults.Add( result );
 }
コード例 #5
0
ファイル: Database.cs プロジェクト: Breeto/MatchMaker
 public void SaveMatchupResults(MatchupResult[] results)
 {
     foreach(var result in results)
     {
         database.GetCollection<MatchupResult>(Collections.MatchupResults).Save(result);
     }
 }
コード例 #6
0
ファイル: Database.cs プロジェクト: Breeto/MatchMaker
 public void SaveMatchupResult( MatchupResult result )
 {
     database
         .GetCollection<MatchupResult>( Collections.MatchupResults )
         .Insert( result );
 }
コード例 #7
0
        private List<int> GetRecentWinLosses(MatchupResult[] results, User user)
        {
            var winLosses = new List<int>();
            var streak = 0;
            foreach(var result in results)
            {
                var onTeam1 = result.Team1UserIds.Contains(user.Id);
                var onTeam2 = result.Team2UserIds.Contains(user.Id);
                if(!onTeam1 && !onTeam2)
                {
                    continue;
                }
                var won = result.Winner == MatchupWinner.Team1 && onTeam1 || result.Winner == MatchupWinner.Team2 && onTeam2;
                if(streak>=0)
                {
                    if(won)
                    {
                        streak++;
                    }
                    else
                    {
                        streak = -1;
                    }
                }
                else
                {
                    if(!won)
                    {
                        streak --;
                    }
                    else
                    {
                        streak = 1;
                    }
                }

                winLosses.Add(streak);

            }

            if(winLosses.Count<=20)
                return winLosses;
            winLosses.RemoveRange(0,winLosses.Count-20);
            return winLosses;
        }
コード例 #8
0
        private List<MapWinLossInformation> GetMapWinPercentages(MatchupResult[] results, User user, List<Map> maps)
        {
            var countDictonary = maps.ToDictionary(map => map.Id, map => new MapWinLossInformation(){Map = map});
            foreach (var result in results)
            {
                var onTeam1 = result.Team1UserIds.Contains(user.Id);
                var onTeam2 = result.Team2UserIds.Contains(user.Id);
                if (!onTeam1 && !onTeam2 || !countDictonary.Keys.Contains(result.MapId))
                {
                    continue;
                }
                var won = result.Winner == MatchupWinner.Team1 && onTeam1 || result.Winner == MatchupWinner.Team2 && onTeam2;
                countDictonary[result.MapId].TimesPlayed++;
                if (won)
                {
                    countDictonary[result.MapId].Wins++;
                }

            }

            foreach (var key in countDictonary.Keys)
            {
                countDictonary[key].Percentage = countDictonary[key].TimesPlayed == 0 ? .5 :  countDictonary[key].Wins/countDictonary[key].TimesPlayed;
            }

            return (from kvpair in countDictonary select kvpair.Value).ToList();
        }
コード例 #9
0
        private Dictionary<Guid, Dictionary<Guid, Link>> GetLinks( MatchupResult[] PreviousGames, User[] players )
        {
            var result = new Dictionary<Guid, Dictionary<Guid, Link>>();
            var playerDictionary = new Dictionary<Guid, User>();
            foreach ( User user in players )
            {
                result.Add( user.Id, new Dictionary<Guid, Link>() );
                playerDictionary.Add( user.Id, user );
            }

            foreach ( MatchupResult matchup in PreviousGames )
            {
                foreach ( Guid id in matchup.Team1UserIds )
                {
                    if ( !playerDictionary.Keys.Contains( id ) )
                    {
                        continue;
                    }
                    foreach ( Guid otherId in matchup.Team1UserIds )
                    {
                        if ( !playerDictionary.Keys.Contains( otherId ) || id == otherId || result[id] == null )
                        {
                            continue;
                        }
                        if ( !result[id].ContainsKey( otherId ) )
                        {
                            result[id].Add( otherId, new Link( playerDictionary[otherId] ) );
                        }
                        result[id][otherId].AddGame( matchup );
                    }
                }
                foreach ( Guid id in matchup.Team2UserIds )
                {
                    if ( !playerDictionary.Keys.Contains( id ) )
                    {
                        continue;
                    }
                    foreach ( Guid otherId in matchup.Team2UserIds )
                    {
                        if ( !playerDictionary.Keys.Contains( otherId ) || id == otherId || result[id] == null )
                        {
                            continue;
                        }
                        if ( !result[id].ContainsKey( otherId ) )
                        {
                            result[id].Add( otherId, new Link( playerDictionary[otherId] ) );
                        }
                        result[id][otherId].AddGame( matchup );
                    }
                }
            }

            return result;
        }
コード例 #10
0
ファイル: Link.cs プロジェクト: Breeto/MatchMaker
 public void AddGame(MatchupResult game)
 {
     if (game.Winner == MatchupWinner.Tie ||(!game.Team1UserIds.Contains(OtherPlayer.Id) && !game.Team2UserIds.Contains(OtherPlayer.Id)))
         return;
     Games.Add(game);
 }