9 #ifndef EMP_GAME_PAYOFF_MATRIX_H 10 #define EMP_GAME_PAYOFF_MATRIX_H 12 #include "../base/array.h" 22 constexpr
size_t to_index(
size_t A,
size_t B)
const {
return A * num_moves + B; }
25 const size_t combos = num_moves * num_moves;
33 void SetVal(
size_t self,
size_t other,
double value) { payoff[to_index(
self,other)] = value; }
34 double &
operator()(
size_t A,
size_t B) {
return payoff[to_index(A,B)]; }
35 double operator()(
size_t A,
size_t B)
const {
return payoff[to_index(A,B)]; }
39 payoff[to_index(0,0)] = u;
40 payoff[to_index(0,1)] = 1.0 + u;
41 payoff[to_index(1,0)] = 0.0;
42 payoff[to_index(1,1)] = 1.0;
46 payoff[to_index(0,0)] = 0;
47 payoff[to_index(0,1)] = 1.0;
48 payoff[to_index(1,0)] = 1.0 - cost;
49 payoff[to_index(1,1)] = 1.0 - cost/2;
52 std::unordered_map<int, double>
AsInput(
size_t player_id)
const {
53 std::unordered_map<int, double> out_map;
54 out_map[-1] = num_moves;
55 for (
size_t i = 0; i < payoff.
size(); i++) {
56 out_map[i] = payoff[i];
std::unordered_map< int, double > AsInput(size_t player_id) const
Definition: PayoffMatrix.h:52
void SetupPD(double u)
Definition: PayoffMatrix.h:38
double operator()(size_t A, size_t B) const
Definition: PayoffMatrix.h:35
void SetVal(size_t self, size_t other, double value)
Definition: PayoffMatrix.h:33
Definition: PayoffMatrix.h:17
size_t size() const
Definition: vector.h:151
void Reset()
Definition: PayoffMatrix.h:31
void SetupSnowdrift(double cost)
Definition: PayoffMatrix.h:45
void resize(size_t new_size)
Definition: vector.h:161
double & operator()(size_t A, size_t B)
Definition: PayoffMatrix.h:34
If we are in emscripten, make sure to include the header.
Definition: array.h:37
PayoffMatrix(size_t _moves=2)
Definition: PayoffMatrix.h:24
size_t move_t
Definition: PayoffMatrix.h:29