A1/hands.h

60 lines
1.7 KiB
C
Raw Permalink Normal View History

#ifndef HANDS_H
#define HANDS_H
#include <istream>
#include <memory>
#include <random>
enum GameResult { Win, Tie, Loss };
class Hand {
public:
// Converts a user-inputted character to the correct instance of Hand.
static std::unique_ptr<Hand> fromChar(char);
// Randomly returns one of the variants of Hand, as generated by a Mersenne
// Twister function seeded by the current unix time
static std::unique_ptr<Hand> generateRandom(std::mt19937&, std::uniform_int_distribution<int>&);
// Returns the lowercase name of this type of hand, for example "rock" or
// "scissors".
virtual std::string getHandName() const = 0;
// Returns if this instance of Hand wins against another instance. The
// returned value is from the perspective of this instance of hand. For
// example, if GameResult::Win is returned, the instance of Hand wins
// against the passed argument Hand.
virtual GameResult compareAgainst(const Hand &) = 0;
};
// List of all types of RPSLS hands that can be played
class Rock : public Hand {
public:
std::string getHandName() const override;
GameResult compareAgainst(const Hand &) override;
};
class Paper : public Hand {
public:
std::string getHandName() const override;
GameResult compareAgainst(const Hand &) override;
};
class Scissors : public Hand {
public:
std::string getHandName() const override;
GameResult compareAgainst(const Hand &) override;
};
class Lizard : public Hand {
public:
std::string getHandName() const override;
GameResult compareAgainst(const Hand &) override;
};
class Spock : public Hand {
public:
std::string getHandName() const override;
GameResult compareAgainst(const Hand &) override;
};
#endif // HANDS_H