diff options
| author | Aiden Woodruff <woodra@rpi.edu> | 2025-11-21 08:53:21 -0500 |
|---|---|---|
| committer | Aiden Woodruff <woodra@rpi.edu> | 2025-11-21 08:53:21 -0500 |
| commit | b7080ba3627aa07de5be3385e62d16d9ea428167 (patch) | |
| tree | cbaea284e7c24c44a6d4b3532b39acefacf00a69 /src | |
| parent | 40d730bad470a8d093d24246c1d6ee21688357ba (diff) | |
| download | tipping-points-b7080ba3627aa07de5be3385e62d16d9ea428167.tar.gz tipping-points-b7080ba3627aa07de5be3385e62d16d9ea428167.tar.bz2 tipping-points-b7080ba3627aa07de5be3385e62d16d9ea428167.zip | |
fix best_move selection
- src/NameGame.cc: replace faulty fraction accounting with simple
std::max_element.
Signed-off-by: Aiden Woodruff <woodra@rpi.edu>
Diffstat (limited to 'src')
| -rw-r--r-- | src/NameGame.cc | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/NameGame.cc b/src/NameGame.cc index 5b79f87..20221f7 100644 --- a/src/NameGame.cc +++ b/src/NameGame.cc | |||
| @@ -120,12 +120,13 @@ int NameGame::best_move(int nId) const { | |||
| 120 | if (votes.count(v)) votes[v] += 1; | 120 | if (votes.count(v)) votes[v] += 1; |
| 121 | else votes[v] = 1; | 121 | else votes[v] = 1; |
| 122 | } | 122 | } |
| 123 | std::map<int, float> fractions; | 123 | if (votes.empty()) return 0; |
| 124 | for (auto kv : votes) fractions[kv.first] = kv.second * 1./mem.Len(); | 124 | int best = std::max_element(votes.begin(), votes.end(), |
| 125 | // Simple majority vote: | 125 | [](const auto& v1, const auto& v2) { |
| 126 | for (auto kv : fractions) | 126 | return v1.second < v2.second; |
| 127 | if (kv.second >= 1./mem.Len()) return kv.first; | 127 | } |
| 128 | return 0; | 128 | )->first; |
| 129 | return best; | ||
| 129 | } | 130 | } |
| 130 | 131 | ||
| 131 | void NameGame::update_memory(int nId, int strategy) { | 132 | void NameGame::update_memory(int nId, int strategy) { |
