Skip to content

Instantly share code, notes, and snippets.

@Pethaf
Created April 13, 2017 10:49
Show Gist options
  • Save Pethaf/dbce33519a7dec5caa3e1fcd6effb2ba to your computer and use it in GitHub Desktop.
Save Pethaf/dbce33519a7dec5caa3e1fcd6effb2ba to your computer and use it in GitHub Desktop.
Override
typedef vector<int> vint;
class Score_Variant
{
public:
virtual ~Score_Variant() = default;
virtual string name() const { return to_str();}
virtual int score(const vint&) = 0;
protected:
Score_Variant() = default;
private:
Score_Variant& operator=(const Score_Variant&) = delete;
Score_Variant(Score_Variant&) = delete;
Score_Variant(Score_Variant&&) = delete;
virtual string to_str() const = 0;
};
class Pair: public Score_Variant{
public:
virtual ~Pair() = default;
Pair() = default;
virtual int score(const vint& diceRolls ) override
{ sort(begin(diceRolls),end(diceRolls));
auto tmp = adjacent_find(rbegin(diceRolls),rend(diceRolls));
if(tmp != rend(diceRolls))
{
return (*tmp)*2;
}
else
{
return 0;
}
}
private:
Pair(const Pair&) = delete;
Pair(Pair&&) = delete;
Pair& operator=(const Pair&) = delete;
virtual string to_str() const override { return "Twos";}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment