Compare commits
No commits in common. "362d7f214d0f1067e4e50d83d3fef9604c6732df" and "d371ebb71667dea1dd1b63a8b249eef28ae3d417" have entirely different histories.
362d7f214d
...
d371ebb716
27
README.md
27
README.md
@ -1,27 +0,0 @@
|
||||
# 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.
|
@ -8,23 +8,10 @@ typedef enum {
|
||||
|
||||
class Player {
|
||||
public:
|
||||
/* Gathered points during the game are stored internally
|
||||
*/
|
||||
long points = 0;
|
||||
/* This is for logging the game
|
||||
*/
|
||||
const char * name;
|
||||
/* Called before facing a new opponent
|
||||
*/
|
||||
virtual void new_game() = 0;
|
||||
/* Called during a match;
|
||||
* the return value is your response
|
||||
*/
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
using namespace std;
|
||||
|
||||
vector<Player *> players;
|
||||
|
||||
const int ROUND_COUNT = 200;
|
||||
|
||||
inline
|
||||
@ -38,39 +39,26 @@ void play_round(Player * const p1, Player * const p2) {
|
||||
Player * const pw = (p1_play == CONFLICT) ? p1 : p2;
|
||||
pw->points += 5;
|
||||
}
|
||||
|
||||
p1->push_result(p2_play);
|
||||
p2->push_result(p1_play);
|
||||
}
|
||||
|
||||
signed main() {
|
||||
/* we seed, rand for you, in case you wish to use it,
|
||||
* please do not re seed it
|
||||
*/
|
||||
srand(time(NULL));
|
||||
|
||||
// YYY: Every player is added here
|
||||
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 h = i + 1; h < players.size(); h++) {
|
||||
printf("%s VS %s\n", players[i]->name, players[h]->name);
|
||||
players[i]->new_game();
|
||||
players[h]->new_game();
|
||||
/* Each game takes some number of turns
|
||||
*/
|
||||
for (int c = 0; c < ROUND_COUNT; c++) {
|
||||
play_round(players[i], players[h]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Results
|
||||
for (const auto &p : players) {
|
||||
printf("%s: %ld\n", p->name, p->points);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user