using System.Collections.Generic; namespace Analizator9000 { /// /// Base scoring utility, for scoring methods which produce the board scores comparing all scores with each other and averaging over the results (e.g. matchpoints, Cavendish IMP). /// abstract class BaseScorer : IScorer { public Dictionary scoreBoard(Dictionary scores) { Dictionary result = new Dictionary(); int scoreCount = 0; foreach (KeyValuePair score in scores) { if (score.Key.Frequency > 0) { // Accumulating number of scores in a board scoreCount += score.Key.Frequency; result[score.Key] = 0; foreach (KeyValuePair otherScore in scores) { if (score.Key != otherScore.Key) // all different scores are compared with the score { result[score.Key] += this.getResultFromScores(score.Value, otherScore.Value) * otherScore.Key.Frequency; } else // and all but one (the score we're calculating) from the same scores { result[score.Key] += this.getResultFromScores(score.Value, otherScore.Value) * (score.Key.Frequency - 1); } } } } // Averaging every score by dividing by a certain factor double divisor = this.getDivisorFromScoreCount(scoreCount); if (divisor > 0) { foreach (KeyValuePair score in scores) { result[score.Key] /= divisor; } } return result; } /// /// Scoring method for comparing two scores /// /// Score to calculate the outcome /// Score to compare to /// Score between two scores in the method used protected abstract double getResultFromScores(long score1, long score2); /// /// Produces averaging factor for specified number of scores on a board /// /// Number of scores in the traveller /// Factor for score average division virtual protected double getDivisorFromScoreCount(int scoreCount) { return scoreCount; } } }