-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_games.cpp
More file actions
97 lines (82 loc) · 3.45 KB
/
test_games.cpp
File metadata and controls
97 lines (82 loc) · 3.45 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include "main.cpp" // Include the main solver
using namespace std;
void testGame(const string& name, const Game2x2& game) {
cout << "\n" << string(60, '=') << endl;
cout << "Testing: " << name << endl;
cout << string(60, '=') << endl;
NormalFormSolver solver(game);
solver.printGame();
// Find Nash equilibria
vector<Equilibrium> nash_equilibria = solver.findAllNashEquilibria();
cout << "Nash Equilibria:" << endl;
if (nash_equilibria.empty()) {
cout << "No Nash equilibria found." << endl;
} else {
for (const auto& eq : nash_equilibria) {
cout << "- " << eq.description << endl;
}
}
// Find non-myopic equilibria
vector<Equilibrium> non_myopic_equilibria = solver.findNonMyopicEquilibria();
cout << "\nNon-Myopic Equilibria:" << endl;
if (non_myopic_equilibria.empty()) {
cout << "No non-myopic equilibria found." << endl;
} else {
for (const auto& eq : non_myopic_equilibria) {
cout << "- " << eq.description << endl;
}
}
cout << endl;
}
int main() {
cout << "=== Testing Different Game Types ===" << endl;
// 1. Prisoner's Dilemma
Game2x2 prisoner_dilemma;
prisoner_dilemma.setPayoff(0, 0, 0, 0.0); // Both cooperate
prisoner_dilemma.setPayoff(0, 0, 1, 3.0);
prisoner_dilemma.setPayoff(0, 1, 0, 0.0); // P1 cooperates, P2 defects
prisoner_dilemma.setPayoff(0, 1, 1, 5.0);
prisoner_dilemma.setPayoff(1, 0, 0, 5.0); // P1 defects, P2 cooperates
prisoner_dilemma.setPayoff(1, 0, 1, 0.0);
prisoner_dilemma.setPayoff(1, 1, 0, 1.0); // Both defect
prisoner_dilemma.setPayoff(1, 1, 1, 1.0);
testGame("Prisoner's Dilemma", prisoner_dilemma);
// 2. Battle of the Sexes
Game2x2 battle_of_sexes;
battle_of_sexes.setPayoff(0, 0, 0, 3.0); // Both prefer same activity
battle_of_sexes.setPayoff(0, 0, 1, 2.0);
battle_of_sexes.setPayoff(0, 1, 0, 0.0); // Different preferences
battle_of_sexes.setPayoff(0, 1, 1, 0.0);
battle_of_sexes.setPayoff(1, 0, 0, 0.0); // Different preferences
battle_of_sexes.setPayoff(1, 0, 1, 0.0);
battle_of_sexes.setPayoff(1, 1, 0, 2.0); // Both prefer same activity
battle_of_sexes.setPayoff(1, 1, 1, 3.0);
testGame("Battle of the Sexes", battle_of_sexes);
// 3. Coordination Game
Game2x2 coordination;
coordination.setPayoff(0, 0, 0, 2.0); // Both choose A
coordination.setPayoff(0, 0, 1, 2.0);
coordination.setPayoff(0, 1, 0, 0.0); // Different choices
coordination.setPayoff(0, 1, 1, 0.0);
coordination.setPayoff(1, 0, 0, 0.0); // Different choices
coordination.setPayoff(1, 0, 1, 0.0);
coordination.setPayoff(1, 1, 0, 1.0); // Both choose B
coordination.setPayoff(1, 1, 1, 1.0);
testGame("Coordination Game", coordination);
// 4. Matching Pennies
Game2x2 matching_pennies;
matching_pennies.setPayoff(0, 0, 0, 1.0); // Same choice
matching_pennies.setPayoff(0, 0, 1, -1.0);
matching_pennies.setPayoff(0, 1, 0, -1.0); // Different choices
matching_pennies.setPayoff(0, 1, 1, 1.0);
matching_pennies.setPayoff(1, 0, 0, -1.0); // Different choices
matching_pennies.setPayoff(1, 0, 1, 1.0);
matching_pennies.setPayoff(1, 1, 0, 1.0); // Same choice
matching_pennies.setPayoff(1, 1, 1, -1.0);
testGame("Matching Pennies", matching_pennies);
return 0;
}