예제 #1
0
 protected GaussianWeightedSumFactor CreatePlayerToTeamSumFactor(
     IList <KeyedVariable <TPlayer, GaussianDistribution> > teamMembers, Variable <GaussianDistribution> sumVariable)
 {
     return(new GaussianWeightedSumFactor(sumVariable, teamMembers.ToArray(),
                                          teamMembers.Select(v => PartialPlay.GetPartialPlayPercentage(v.Key)).
                                          ToArray()));
 }
예제 #2
0
        private static Matrix CreatePlayerTeamAssignmentMatrix <TPlayer>(
            IList <IDictionary <TPlayer, Rating> > teamAssignmentsList, int totalPlayers)
        {
            // The team assignment matrix is often referred to as the "A" matrix. It's a matrix whose rows represent the players
            // and the columns represent teams. At Matrix[row, column] represents that player[row] is on team[col]
            // Positive values represent an assignment and a negative value means that we subtract the value of the next
            // team since we're dealing with pairs. This means that this matrix always has teams - 1 columns.
            // The only other tricky thing is that values represent the play percentage.

            // For example, consider a 3 team game where team1 is just player1, team 2 is player 2 and player 3, and
            // team3 is just player 4. Furthermore, player 2 and player 3 on team 2 played 25% and 75% of the time
            // (e.g. partial play), the A matrix would be:

            // A = this 4x2 matrix:
            // |  1.00  0.00 |
            // | -0.25  0.25 |
            // | -0.75  0.75 |
            // |  0.00 -1.00 |

            var playerAssignments    = new List <IEnumerable <double> >();
            int totalPreviousPlayers = 0;

            for (int i = 0; i < teamAssignmentsList.Count - 1; i++)
            {
                IDictionary <TPlayer, Rating> currentTeam = teamAssignmentsList[i];

                // Need to add in 0's for all the previous players, since they're not
                // on this team
                var currentRowValues = new List <double>(new double[totalPreviousPlayers]);
                playerAssignments.Add(currentRowValues);

                foreach (var currentRating in currentTeam)
                {
                    currentRowValues.Add(PartialPlay.GetPartialPlayPercentage(currentRating.Key));
                    // indicates the player is on the team
                    totalPreviousPlayers++;
                }

                IDictionary <TPlayer, Rating> nextTeam = teamAssignmentsList[i + 1];
                foreach (var nextTeamPlayerPair in nextTeam)
                {
                    // Add a -1 * playing time to represent the difference
                    currentRowValues.Add(-1 * PartialPlay.GetPartialPlayPercentage(nextTeamPlayerPair.Key));
                }
            }

            var playerTeamAssignmentsMatrix = new Matrix(totalPlayers, teamAssignmentsList.Count - 1, playerAssignments);

            return(playerTeamAssignmentsMatrix);
        }