diff options
| author | Aiden Woodruff <woodra@rpi.edu> | 2025-11-18 17:20:43 -0500 |
|---|---|---|
| committer | Aiden Woodruff <woodra@rpi.edu> | 2025-11-18 17:20:43 -0500 |
| commit | bdf08f745ed7373431b8d911449fd77068258abe (patch) | |
| tree | c58517518be1a825975ebcd6abf78d611da61d78 /src | |
| parent | 9008a72760c8f04ef559c72ee2d7ef9d9b61a608 (diff) | |
| download | tipping-points-bdf08f745ed7373431b8d911449fd77068258abe.tar.gz tipping-points-bdf08f745ed7373431b8d911449fd77068258abe.tar.bz2 tipping-points-bdf08f745ed7373431b8d911449fd77068258abe.zip | |
only one strategy per round
- src/NameGame.cc (runRound): fixed code so that only speaker chooses a
strategy each round. this matches BestResponseNameGame.R
- renamed variables to just strategy.
- updated record call.
- (run): updated average calculation per round.
- (writeRecord): updated header and row code.
- src/NameGame.h: updated Record struct to remove hearer info.
Signed-off-by: Aiden Woodruff <woodra@rpi.edu>
Diffstat (limited to 'src')
| -rw-r--r-- | src/NameGame.cc | 32 | ||||
| -rw-r--r-- | src/NameGame.h | 2 |
2 files changed, 10 insertions, 24 deletions
diff --git a/src/NameGame.cc b/src/NameGame.cc index 2dd64c0..3fc314e 100644 --- a/src/NameGame.cc +++ b/src/NameGame.cc | |||
| @@ -79,7 +79,7 @@ void NameGame::run(int rounds) { | |||
| 79 | // Report average plays. | 79 | // Report average plays. |
| 80 | float avg = 0; | 80 | float avg = 0; |
| 81 | for (size_t i = srlen; i < strategy_record.size(); ++i) { | 81 | for (size_t i = srlen; i < strategy_record.size(); ++i) { |
| 82 | avg += strategy_record[i].s_strategy + strategy_record[i].h_strategy; | 82 | avg += strategy_record[i].strategy; |
| 83 | } | 83 | } |
| 84 | avg /= strategy_record.size() - srlen; | 84 | avg /= strategy_record.size() - srlen; |
| 85 | std::cout << avg << std::endl; | 85 | std::cout << avg << std::endl; |
| @@ -94,30 +94,18 @@ void NameGame::runRound(int r) { | |||
| 94 | ); | 94 | ); |
| 95 | 95 | ||
| 96 | // Speaker chooses best strategy. | 96 | // Speaker chooses best strategy. |
| 97 | int s_strategy = best_move(speaker.GetId()); | 97 | int strategy = best_move(speaker.GetId()); |
| 98 | if (verbose_flag) { | 98 | if (verbose_flag) { |
| 99 | std::cout << "speaker (" << speaker.GetId() << " " | 99 | std::cout << "speaker (" << speaker.GetId() << " " |
| 100 | << std::boolalpha << speaker().Val1 | 100 | << std::boolalpha << speaker().Val1 |
| 101 | << ") chose: " << s_strategy << std::endl; | 101 | << ") chose: " << strategy << std::endl; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | // Listener updates memory. | 104 | // Hearer updates memory. |
| 105 | update_memory(hearer.GetId(), s_strategy); | 105 | update_memory(hearer.GetId(), strategy); |
| 106 | 106 | ||
| 107 | // Listener chooses best strategy. | 107 | // Strategy is recorded. |
| 108 | int h_strategy = best_move(hearer.GetId()); | 108 | strategy_record.push_back({r, speaker.GetId(), speaker().Val1, strategy}); |
| 109 | if (verbose_flag) { | ||
| 110 | std::cout << "hearer (" << hearer.GetId() << " " | ||
| 111 | << std::boolalpha << hearer().Val1 | ||
| 112 | << ") chose: " << h_strategy << std::endl; | ||
| 113 | } | ||
| 114 | |||
| 115 | // Speaker updates memory. | ||
| 116 | update_memory(speaker.GetId(), h_strategy); | ||
| 117 | strategy_record.push_back({ | ||
| 118 | r, speaker.GetId(), speaker().Val1, | ||
| 119 | hearer.GetId(), hearer().Val1, s_strategy, h_strategy | ||
| 120 | }); | ||
| 121 | } | 109 | } |
| 122 | 110 | ||
| 123 | int NameGame::best_move(int nId) const { | 111 | int NameGame::best_move(int nId) const { |
| @@ -154,13 +142,11 @@ void NameGame::writeRecord(const char* fname, bool append) { | |||
| 154 | else mode |= std::ios::trunc; | 142 | else mode |= std::ios::trunc; |
| 155 | std::fstream f(fname, mode); | 143 | std::fstream f(fname, mode); |
| 156 | if (!append || f.tellp() == 0) { | 144 | if (!append || f.tellp() == 0) { |
| 157 | f << "group_size,cm_size,memlen,round,speaker,speaker_type," | 145 | f << "group_size,cm_size,memlen,round,speaker,committed,strategy\n"; |
| 158 | "hearer,hearer_type,speaker_strategy,hearer_strategy\n"; | ||
| 159 | } | 146 | } |
| 160 | for (const auto& r : strategy_record) { | 147 | for (const auto& r : strategy_record) { |
| 161 | f << gsize << ',' << cmsize << ',' << memlen << ',' << r.round << ',' | 148 | f << gsize << ',' << cmsize << ',' << memlen << ',' << r.round << ',' |
| 162 | << r.speaker << ',' << r.s_cm << ',' << r.hearer << ',' << r.h_cm << ',' | 149 | << r.speaker << ',' << r.committed << ',' << r.strategy << '\n'; |
| 163 | << r.s_strategy << ',' << r.h_strategy << '\n'; | ||
| 164 | } | 150 | } |
| 165 | } | 151 | } |
| 166 | 152 | ||
diff --git a/src/NameGame.h b/src/NameGame.h index eae45f3..7a9638a 100644 --- a/src/NameGame.h +++ b/src/NameGame.h | |||
| @@ -32,7 +32,7 @@ private: | |||
| 32 | std::uniform_int_distribution<> dist; | 32 | std::uniform_int_distribution<> dist; |
| 33 | TNodeNet<TPair<TBool, TIntV>> graph; | 33 | TNodeNet<TPair<TBool, TIntV>> graph; |
| 34 | struct Record { | 34 | struct Record { |
| 35 | int round, speaker, s_cm, hearer, h_cm, s_strategy, h_strategy; | 35 | int round, speaker, committed, strategy; |
| 36 | }; | 36 | }; |
| 37 | std::vector<Record> strategy_record; | 37 | std::vector<Record> strategy_record; |
| 38 | }; // class NameGame | 38 | }; // class NameGame |
