Skip to content

Commit

Permalink
Ensure good matchups per gender across teams
Browse files Browse the repository at this point in the history
Previously, two teams would be considered "even" if one had
3 experienced males and 3 experienced females. Since males
generally mark males and females mark females, this would create
a lot of poor matchups on the field.

With this change, team allocation prefers combinations where
not only is the overall skill the same between teams, but also the
amount of skill per gender.
  • Loading branch information
smashery committed Sep 5, 2015
1 parent 46b87c7 commit baf4a16
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions KingsAndQueensHat/KingsAndQueensHat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Model\PlayerEventArgs.cs" />
<Compile Include="Model\TournamentSettings.cs" />
<Compile Include="Persistence\StorageLocator.cs" />
<Compile Include="TeamGeneration\UnevenGenderSkillPenalty.cs" />
<Compile Include="ViewModel\GenderRanking.cs" />
<Compile Include="Persistence\InvalidRoundException.cs" />
<Compile Include="Properties\Annotations.cs" />
Expand Down
9 changes: 9 additions & 0 deletions KingsAndQueensHat/Model/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ public int TotalSkill
get { return Players.Sum(p => p.SkillValue); }
}

[XmlIgnore]
public Dictionary<Gender, int> GenderSkills
{
get
{
return Players.GroupBy(p => p.Gender).Select(g => new {g.Key, Skill = g.Sum(p => p.SkillValue)}).ToDictionary(x => x.Key, x => x.Skill);
}
}

[XmlIgnore]
public int PlayerCount
{
Expand Down
3 changes: 2 additions & 1 deletion KingsAndQueensHat/Model/Tournament.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public async Task CreateNewRound(int teamCount, CancellationToken cancel)
var penalty1 = new UnevenSkillPenalty();
var penalty3 = new TooManyWinnersPenalty(PlayerProvider);
var penalty4 = new RangeOfSkillsPenalty();
var penalties = new IPenalty[] { penalty1, _playerPairings, penalty3, penalty4 };
var penalty5 = new UnevenGenderSkillPenalty();
var penalties = new IPenalty[] { penalty1, _playerPairings, penalty3, penalty4, penalty5 };

var teams = await teamCreator.CreateApproximatelyOptimalTeams(penalties, PlayerProvider, numTeamGens, teamCount, cancel);

Expand Down
34 changes: 34 additions & 0 deletions KingsAndQueensHat/TeamGeneration/UnevenGenderSkillPenalty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using KingsAndQueensHat.Model;

namespace KingsAndQueensHat.TeamGeneration
{
/// <summary>
/// Penalise team allocations that leave some teams with a particular dominant gender
/// , while others do not
/// </summary>
public class UnevenGenderSkillPenalty : IPenalty
{
public double ScorePenalty(List<Team> teams)
{
var scores = teams.Select(team => team.GenderSkills).ToList();
int result = 0;
foreach (var gender in new[] { Gender.Male, Gender.Female })
{
var total = scores.Sum(s => s[gender]);
var teamCount = teams.Count;
var expectedTeamGenderSkill = total / teamCount;

// Sum the deviations from the expected team skill
result += scores.Sum(s => Math.Abs(s[gender] - expectedTeamGenderSkill));
}
return result;
}

public double Weighting { get { return 1.0; } }
}
}

0 comments on commit baf4a16

Please sign in to comment.