예제 #1
0
 public Player GetOpponent(Player player)
 {
     if (!ContainsPlayers(player))
     {
         throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Player '{0}' does not exist in this pairing", player.Name));
     }
     return player.Equals(Player1) ? Player2 : Player1;
 }
예제 #2
0
        public void Swap(Player first, Player second)
        {
            var pairing1 = Pairings.FirstOrDefault(i => i.ContainsPlayers(first));
            var pairing2 = Pairings.FirstOrDefault(i => i.ContainsPlayers(second));

            if (pairing1 == null || pairing2 == null)
            {
                throw new ArgumentException("Could not swap players! Requested player was not found");
            }

            pairing1.ReplacePlayer(first, second);
            pairing2.ReplacePlayer(second, first);
        }
예제 #3
0
 public void ReplacePlayer(Player initial, Player replacement)
 {
     if (Player1.Equals(initial))
     {
         Player1 = replacement;
     }
     else if (Player2.Equals(initial))
     {
         Player2 = replacement;
     }
     else
     {
         throw new ArgumentException("Requested player could not be found!");
     }
 }
예제 #4
0
 public int GetPlayerScore(Player player)
 {
     foreach (var i in Pairings)
     {
         if (player.Equals(i.Player1))
         {
             return i.P1Score;
         }
         if (player.Equals(i.Player2))
         {
             return i.P2Score;
         }
     }
     throw new ArgumentException("Player not found!");
 }
예제 #5
0
 public Pairing(Player p1, Player p2)
 {
     Player1 = p1;
     Player2 = p2;
 }
 private static void VerifyPlayersStandingWithScore(KeyValuePair<Player, int> standing, Player player, int score)
 {
     Assert.Equal(player, standing.Key);
     Assert.Equal(score, standing.Value);
 }
        public void Swap_ChangesPlacesOfTwoPlayersInRound()
        {
            var p1 = new Player { Name = "P1" };
            var p2 = new Player { Name = "P2" };
            var p3 = new Player { Name = "P3" };
            var p4 = new Player { Name = "P4" };
            var tournament = new Tournament(new PairingGenerator(), 1) { Players = new[] { p1, p2, p3, p4 } };
            var pairings = tournament.SwissPairings().ToList();
            var round = tournament.Rounds.ElementAt(0);
            round.Pairings = pairings;

            round.Swap(pairings.ElementAt(0).Player1, pairings.ElementAt(1).Player2);
            Assert.Equal(p4, pairings[0].Player1);
            Assert.Equal(p2, pairings[0].Player2);
            Assert.Equal(p3, pairings[1].Player1);
            Assert.Equal(p1, pairings[1].Player2);

            round.Swap(p2, p1);
            Assert.Equal(p4, pairings[0].Player1);
            Assert.Equal(p1, pairings[0].Player2);
            Assert.Equal(p3, pairings[1].Player1);
            Assert.Equal(p2, pairings[1].Player2);
        }