PurplePen.RelayVariations.ScoreLegAssignment C# (CSharp) Method

ScoreLegAssignment() private method

private ScoreLegAssignment ( int leg, TeamAssignment teamAssignment ) : int
leg int
teamAssignment TeamAssignment
return int
        private int ScoreLegAssignment(int leg, TeamAssignment teamAssignment)
        {
            int score = 0;

            // Check 1: check again previous teams on same leg.
            int allowedDuplicates = (results.Count / minUniquePaths);
            if (allowedDuplicates >= 1) {
                allowedDuplicates += (int)Math.Ceiling((double)allowedDuplicates / 3); // allow some slop after all options used once.
            }
            int duplicates = 0;
            for (int i = 0; i < results.Count; ++i) {
                if (results[i].LegEquals(leg, teamAssignment, leg))
                    ++duplicates;
            }

            score += Math.Max(0, (duplicates - allowedDuplicates));

            if (numberLegs <= minUniquePaths) {
                // Check 2: check against previous legs on same team, if they should be unique
                for (int otherLeg = 0; otherLeg < leg; ++otherLeg) {
                    if (teamAssignment.LegEquals(leg, teamAssignment, otherLeg))
                        score += 10;
                }
            }

            return score;
        }