summaryrefslogtreecommitdiff
path: root/Analizator9000/Analizator9000/BaseScorer.cs
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2014-12-22 17:27:32 +0000
committeremkael <emkael@tlen.pl>2014-12-22 17:27:32 +0000
commit78b88a41a23a2b4630ca82024664673559623b5a (patch)
tree3cc677f9ab04ee7c58accd09c99c6191d7b3e7f1 /Analizator9000/Analizator9000/BaseScorer.cs
parentc113941d5b292a9d65954b0e4b640ffd025d0631 (diff)
* board scorers (matchpoint, IMPs)
git-svn-id: https://svn.emkael.info/an9k@38 05ec0d5d-773b-4d93-9e23-c81a7ac79feb
Diffstat (limited to 'Analizator9000/Analizator9000/BaseScorer.cs')
-rw-r--r--Analizator9000/Analizator9000/BaseScorer.cs65
1 files changed, 65 insertions, 0 deletions
diff --git a/Analizator9000/Analizator9000/BaseScorer.cs b/Analizator9000/Analizator9000/BaseScorer.cs
new file mode 100644
index 0000000..d291e47
--- /dev/null
+++ b/Analizator9000/Analizator9000/BaseScorer.cs
@@ -0,0 +1,65 @@
+using System.Collections.Generic;
+
+namespace Analizator9000
+{
+ /// <summary>
+ /// 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).
+ /// </summary>
+ abstract class BaseScorer : IScorer
+ {
+ public Dictionary<Contract, double> scoreBoard(Dictionary<Contract, long> scores)
+ {
+ Dictionary<Contract, double> result = new Dictionary<Contract, double>();
+ int scoreCount = 0;
+ foreach (KeyValuePair<Contract, long> 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<Contract, long> 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<Contract, long> score in scores)
+ {
+
+ result[score.Key] /= divisor;
+ }
+ }
+ return result;
+ }
+
+ /// <summary>
+ /// Scoring method for comparing two scores
+ /// </summary>
+ /// <param name="score1">Score to calculate the outcome</param>
+ /// <param name="score2">Score to compare to</param>
+ /// <returns>Score between two scores in the method used</returns>
+ protected abstract double getResultFromScores(long score1, long score2);
+
+ /// <summary>
+ /// Produces averaging factor for specified number of scores on a board
+ /// </summary>
+ /// <param name="scoreCount">Number of scores in the traveller</param>
+ /// <returns>Factor for score average division</returns>
+ virtual protected double getDivisorFromScoreCount(int scoreCount)
+ {
+ return scoreCount;
+ }
+ }
+}