helpful comments
This commit is contained in:
parent
0db64ca2f5
commit
5208bd7a9e
@ -8,10 +8,23 @@ typedef enum {
|
|||||||
|
|
||||||
class Player {
|
class Player {
|
||||||
public:
|
public:
|
||||||
long points = 0;
|
/* Gathered points during the game are stored internally
|
||||||
|
*/
|
||||||
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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,28 +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);
|
p1->push_result(p2_play);
|
||||||
p2->push_result(p1_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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user