aboutsummaryrefslogtreecommitdiffstats
path: root/src/NameGame.h
blob: abd9d6da27af864b9d1dde8ebb63938175b13885 (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
#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();
	void run(int rounds);
	void writeRecord(const char* fname);

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, hearer, s_strategy, h_strategy;
	};
	std::vector<Record> strategy_record;
}; // class NameGame

} // namespace tp

#endif // TIPPING_POINTS_NAMEGAME_H