blob: 0b02a151c9f0435ae9a3855dd1d1b0375ac82817 (
plain) (
blame)
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
|
#ifndef TIPPING_POINTS_NAMEGAME_H
#define TIPPING_POINTS_NAMEGAME_H
#include <random>
#include <tuple>
#include <vector>
#include <Snap.h>
namespace tp {
class NameGame {
public:
NameGame(int group_size, int cm_size, int memory = 12);
void setCMsize(int cm_size);
void initGraph();
void initMemory();
void clearRecord();
/**
* \brief Run the game.
* \return number of non-committed players who would choose the new strategy
*/
int run(int rounds);
void writeRecord(const char* fname, bool append = false);
protected:
int best_move(int nId) const;
void update_memory(int nId, int strategy);
private:
void runRound(int r);
int gsize, cmsize, memlen;
std::mt19937 rng;
std::uniform_int_distribution<> dist;
TNodeNet<TPair<TBool, TIntV>> graph;
struct Record {
int round, speaker, committed, strategy;
};
std::vector<Record> strategy_record;
}; // class NameGame
} // namespace tp
#endif // TIPPING_POINTS_NAMEGAME_H
|