-
Notifications
You must be signed in to change notification settings - Fork 0
/
NimStateStore.cs
48 lines (36 loc) · 1.15 KB
/
NimStateStore.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections.Generic;
namespace Nim {
public class NimStateStore {
public Dictionary<NimState, NimScore> Scores {
get;
private set;
}
public NimStateStore() {
Scores = new Dictionary<NimState, NimScore>();
}
public double GetScore(NimState state) {
NimScore score;
return (Scores.TryGetValue(state, out score)) ? score.Score : 0;
}
public void AddScore(NimState state, double rawScore) {
NimScore score;
if (Scores.TryGetValue(state, out score)) {
score.Add(rawScore);
} else {
score = new NimScore();
score.Add(rawScore);
Scores.Add(state, score);
}
}
public float GetWeight() {
double consensus = 0;
short count = 0;
foreach (KeyValuePair<NimState, NimScore> keyValuePair in Scores) {
consensus += keyValuePair.Value.Score;
count++;
}
consensus /= count;
return (float) (consensus);
}
}
}