aboutsummaryrefslogtreecommitdiffstats
path: root/src/NameGame.h
blob: 0c0552e031c20311fc4ab0f22544b4a5cf2265c7 (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
47
48
49
50
51
52
53
54
#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 seed(int s);
	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);
	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,
#ifdef TP_MEMLIST
		TIntL
#else
		TIntV
#endif
	>> graph;
	struct Record {
		int round, speaker, committed, strategy;
	};
	std::vector<Record> strategy_record;
}; // class NameGame

} // namespace tp

#endif // TIPPING_POINTS_NAMEGAME_H