aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAiden Woodruff <woodra@rpi.edu>2025-11-21 11:03:49 -0500
committerAiden Woodruff <woodra@rpi.edu>2025-11-21 11:03:49 -0500
commit232c1c76d97bea6622f8abdd99f6709590f1cead (patch)
tree05970a3e5caf09139757291c222406b8dd369f1a /src
parentb7080ba3627aa07de5be3385e62d16d9ea428167 (diff)
downloadtipping-points-232c1c76d97bea6622f8abdd99f6709590f1cead.tar.gz
tipping-points-232c1c76d97bea6622f8abdd99f6709590f1cead.tar.bz2
tipping-points-232c1c76d97bea6622f8abdd99f6709590f1cead.zip
change main to one run game
- src/main.cc: run only one game with prescribed settings and output the number of new strategy plays. - src/NameGame.h: change NameGame::run to return an int which is the number of non-committed players that changed their mind. - src/NameGame.cc (run): do not display average for brevity. - output the uncommitted new strategy plays. Signed-off-by: Aiden Woodruff <woodra@rpi.edu>
Diffstat (limited to 'src')
-rw-r--r--src/NameGame.cc10
-rw-r--r--src/NameGame.h6
-rw-r--r--src/main.cc18
3 files changed, 19 insertions, 15 deletions
diff --git a/src/NameGame.cc b/src/NameGame.cc
index 20221f7..e427542 100644
--- a/src/NameGame.cc
+++ b/src/NameGame.cc
@@ -72,7 +72,7 @@ void NameGame::initMemory() {
72 } 72 }
73} 73}
74 74
75void NameGame::run(int rounds) { 75int NameGame::run(int rounds) {
76 if (rounds < 0) throw std::invalid_argument("NameGame::run rounds < 0"); 76 if (rounds < 0) throw std::invalid_argument("NameGame::run rounds < 0");
77 size_t srlen = strategy_record.size(); 77 size_t srlen = strategy_record.size();
78 for (int i = 0; i < rounds; ++i) runRound(i); 78 for (int i = 0; i < rounds; ++i) runRound(i);
@@ -83,7 +83,13 @@ void NameGame::run(int rounds) {
83 avg += strategy_record[i].strategy; 83 avg += strategy_record[i].strategy;
84 } 84 }
85 avg /= strategy_record.size() - srlen; 85 avg /= strategy_record.size() - srlen;
86 std::cout << avg << std::endl; 86 // std::cout << avg << std::endl;
87 int plays = 0;
88 for (int i = strategy_record.size() - gsize; i < strategy_record.size(); ++i) {
89 if (!strategy_record[i].committed && strategy_record[i].strategy == 1)
90 ++plays;
91 }
92 return plays;
87} 93}
88 94
89void NameGame::runRound(int r) { 95void NameGame::runRound(int r) {
diff --git a/src/NameGame.h b/src/NameGame.h
index 7a9638a..0b02a15 100644
--- a/src/NameGame.h
+++ b/src/NameGame.h
@@ -18,7 +18,11 @@ public:
18 void initGraph(); 18 void initGraph();
19 void initMemory(); 19 void initMemory();
20 void clearRecord(); 20 void clearRecord();
21 void run(int rounds); 21 /**
22 * \brief Run the game.
23 * \return number of non-committed players who would choose the new strategy
24 */
25 int run(int rounds);
22 void writeRecord(const char* fname, bool append = false); 26 void writeRecord(const char* fname, bool append = false);
23 27
24protected: 28protected:
diff --git a/src/main.cc b/src/main.cc
index f828b27..f8776eb 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -3,18 +3,12 @@
3#include "NameGame.h" 3#include "NameGame.h"
4 4
5int main(int argc, char* argv[]) { 5int main(int argc, char* argv[]) {
6 int group_size = 1000; 6 int group_size = 1000, cmsize = 292;
7 tp::NameGame namegame(group_size, 0, 12); 7 tp::NameGame namegame(group_size, cmsize, 12);
8 int cmperc_start = 18; 8 std::cout << "CM " << cmsize << " / " << group_size << std::endl;
9 for (int cmperc = cmperc_start; cmperc < 28; cmperc += 2) { 9 int a = namegame.run(group_size * 1000);
10 int cmsize = group_size * cmperc / 100; 10 std::cout << "Non-committed new strategy plays in the last N runs: " << a << std::endl;
11 namegame.clearRecord(); 11 namegame.writeRecord("strategy_record.csv");
12 namegame.setCMsize(cmsize);
13 namegame.initMemory();
14 std::cout << "CM " << cmsize << " / " << group_size << std::endl;
15 namegame.run(group_size * 1000);
16 namegame.writeRecord("strategy_record.csv", cmperc != cmperc_start);
17 }
18 return 0; 12 return 0;
19} 13}
20 14