public override bool ApplyPairing(TournamentPairing pairing)
        {
            if (pairing == null)
            {
                throw new ArgumentNullException("pairing");
            }

            return(false);
        }
        public override bool ApplyPairing(TournamentPairing pairing)
        {
            if (pairing == null)
            {
                throw new ArgumentNullException("pairing");
            }

            if (Locked)
            {
                // If we (and, all of our decentants) are decided, return false, indicating that no node below us is in a state that needs a score.
                return(false);
            }

            if (pairing.ContestantScores.Count != 2 || pairing.ContestantScores[0] == null || pairing.ContestantScores[1] == null || pairing.ContestantScores[0].Contestant == null || pairing.ContestantScores[1].Contestant == null)
            {
                // If the pairing did not contain exactly two teams, or if either of the teams passed was null.
                throw new ArgumentException("A bye was passed as a pairing.", "pairing");
            }

            if (previousWinnerNode.IsDecided && stayNode.IsDecided && !(previousWinnerNode.Score != null || stayNode.Score != null))
            {
                // If our component nodes have played out, but we haven't
                var teamA  = pairing.ContestantScores[0].Contestant;
                var scoreA = pairing.ContestantScores[0].Score;
                var teamB  = pairing.ContestantScores[1].Contestant;
                var scoreB = pairing.ContestantScores[1].Score;

                if (previousWinnerNode.Team.Identity == teamB.Identity && stayNode.Team.Identity == teamA.Identity)
                {
                    // If the order of the pairing is reversed, we will normalize the pairing to us.
                    var teamSwap = teamA;
                    teamB = teamA;
                    teamA = teamSwap;

                    var scoreSwap = scoreA;
                    scoreB = scoreA;
                    scoreA = scoreSwap;
                }

                if (previousWinnerNode.Team.Identity == teamA.Identity && stayNode.Team.Identity == teamB.Identity)
                {
                    // If we are a match, assign the scores.
                    previousWinnerNode.Score = scoreA;
                    stayNode.Score           = scoreB;
                    Lock();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return((!previousWinnerNode.IsDecided && previousWinnerNode.ApplyPairing(pairing)) || (!stayNode.IsDecided && stayNode.ApplyPairing(pairing)));
            }
        }
        public override bool ApplyPairing(TournamentPairing pairing)
        {
            if (pairing == null)
            {
                throw new ArgumentNullException("pairing");
            }

            if (Locked)
            {
                // If we (and, all of our decentants) are decided, return false, indicating that no node below us is in a state that needs a score.
                return(false);
            }

            if (!nodeA.IsDecided || !nodeA.Locked || !nodeB.IsDecided || !nodeB.Locked)
            {
                return((!nodeA.IsDecided && nodeA.ApplyPairing(pairing)) || (!nodeB.IsDecided && nodeB.ApplyPairing(pairing)));
            }
            else
            {
                var teamA  = pairing.ContestantScores[0].Contestant;
                var scoreA = pairing.ContestantScores[0].Score;
                var teamB  = pairing.ContestantScores[1].Contestant;
                var scoreB = pairing.ContestantScores[1].Score;

                if (teamA == null)
                {
                    teamA  = teamB;
                    scoreA = scoreB;
                    teamB  = null;
                    scoreB = null;
                }

                if (!TeamsMatch(teamA, nodeA.Team) || !TeamsMatch(teamB, nodeB.Team))
                {
                    var teamSwap  = teamA;
                    var scoreSwap = scoreA;
                    teamA  = teamB;
                    scoreA = scoreB;
                    teamB  = teamSwap;
                    scoreB = scoreSwap;
                }

                if (TeamsMatch(teamA, nodeA.Team) && TeamsMatch(teamB, nodeB.Team))
                {
                    nodeA.Score = scoreA;
                    nodeB.Score = scoreB;
                    Lock();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        public override bool ApplyPairing(TournamentPairing pairing)
        {
            if (pairing == null)
            {
                throw new ArgumentNullException("pairing");
            }

            if (IsDecided)
            {
                return(false);
            }
            else
            {
                return(decider.ApplyPairing(pairing));
            }
        }
 public abstract bool ApplyPairing(TournamentPairing pairing);