Compare commits

...

3 Commits

Author SHA1 Message Date
362d7f214d +readme 2024-06-29 00:29:53 +02:00
5208bd7a9e helpful comments 2024-06-29 00:29:47 +02:00
0db64ca2f5 doomer observation 2024-06-29 00:29:35 +02:00
3 changed files with 54 additions and 2 deletions

27
README.md Normal file
View File

@ -0,0 +1,27 @@
# Chad Game Theory Tournament
All is based on the Prisoner's dilemma.
The tournament consists of consecutive games which consists of matches.
In each match there are 2 players.
Players must make a binary choice between `COOPERATE` and `CONFLICT`.
Below is a table of all possible out comes:
| Players | Action | Reward |
| :------: | :-------: | :----: |
| Player 1 | COOPERATE | 3 |
| Player 2 | COOPERATE | 3 |
| :------: | :-------: | :----: |
| Player 1 | COOPERATE | 0 |
| Player 2 | CONFLICT | 5 |
| :------: | :-------: | :----: |
| Player 1 | CONFLICT | 5 |
| Player 2 | COOPERATE | 0 |
| :------: | :-------: | :----: |
| Player 1 | CONFLICT | 1 |
| Player 2 | CONFLICT | 1 |
The player with the most points by the end of the Tournament wins.
To play, submit a header file with your subclass implementation of `Player`.
Comments will further aid you.

View File

@ -8,10 +8,23 @@ typedef enum {
class Player { class Player {
public: public:
/* Gathered points during the game are stored internally
*/
long points = 0; long points = 0;
/* This is for logging the game
*/
const char * name; const char * name;
/* Called before facing a new opponent
*/
virtual void new_game() = 0; virtual void new_game() = 0;
/* Called during a match;
* the return value is your response
*/
virtual reaction_t play() = 0; virtual reaction_t play() = 0;
/* Called after the match;
* the argument signals what your opponent played;
* you may use/store this information as you wish
*/
virtual void push_result(reaction_t opponents_last_reaction) = 0; virtual void push_result(reaction_t opponents_last_reaction) = 0;
}; };

View File

@ -9,7 +9,6 @@
using namespace std; using namespace std;
vector<Player *> players; vector<Player *> players;
const int ROUND_COUNT = 200; const int ROUND_COUNT = 200;
inline inline
@ -39,26 +38,39 @@ void play_round(Player * const p1, Player * const p2) {
Player * const pw = (p1_play == CONFLICT) ? p1 : p2; Player * const pw = (p1_play == CONFLICT) ? p1 : p2;
pw->points += 5; pw->points += 5;
} }
p1->push_result(p2_play);
p2->push_result(p1_play);
} }
signed main() { signed main() {
/* we seed, rand for you, in case you wish to use it,
* please do not re seed it
*/
srand(time(NULL)); srand(time(NULL));
// YYY: Every player is added here
players.push_back(new RandomPlayer()); players.push_back(new RandomPlayer());
players.push_back(new RandomPlayer()); players.push_back(new RandomPlayer());
players.push_back(new RandomPlayer()); players.push_back(new RandomPlayer());
// --
/* Every players playes with every player exactly once
*/
for (int i = 0; i < players.size() - 1; i++) { for (int i = 0; i < players.size() - 1; i++) {
for (int h = i + 1; h < players.size(); h++) { for (int h = i + 1; h < players.size(); h++) {
printf("%s VS %s\n", players[i]->name, players[h]->name); printf("%s VS %s\n", players[i]->name, players[h]->name);
players[i]->new_game(); players[i]->new_game();
players[h]->new_game(); players[h]->new_game();
/* Each game takes some number of turns
*/
for (int c = 0; c < ROUND_COUNT; c++) { for (int c = 0; c < ROUND_COUNT; c++) {
play_round(players[i], players[h]); play_round(players[i], players[h]);
} }
} }
} }
// Results
for (const auto &p : players) { for (const auto &p : players) {
printf("%s: %ld\n", p->name, p->points); printf("%s: %ld\n", p->name, p->points);
} }