Skip to content

Instantly share code, notes, and snippets.

@prestonvasquez
Last active February 14, 2023 04:38
Show Gist options
  • Save prestonvasquez/6c67b70e2705394a91a304010fa3a458 to your computer and use it in GitHub Desktop.
Save prestonvasquez/6c67b70e2705394a91a304010fa3a458 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
// Base class
class Player {
public:
// pure virtual function providing interface framework.
virtual int getMove() = 0;
};
// Derived classes
class Human: public Player {
public:
int getMove() {
// TODO: add logic
return 1;
}
};
class Computer: public Player {
public:
int getMove() {
// TODO: add logic
return 0;
}
};
int battle(Player &p1, Player &p2) {
return p1.getMove() + p2.getMove();
}
int main(void) {
Human p1;
Computer p2;
cout << "value: " << battle(p1, p2) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment