Add .clang-format and apply it
This commit is contained in:
@@ -15,8 +15,10 @@ using Cards = std::list<Card>;
|
||||
using Score = unsigned long;
|
||||
using Hash = std::string;
|
||||
|
||||
struct Player {
|
||||
Player(std::istream &is) {
|
||||
struct Player
|
||||
{
|
||||
Player(std::istream& is)
|
||||
{
|
||||
std::string line;
|
||||
if (!std::getline(is, name_)) {
|
||||
assert(false);
|
||||
@@ -35,7 +37,8 @@ struct Player {
|
||||
void push_back(Card c) { cards_.push_back(c); }
|
||||
std::size_t size() const { return cards_.size(); }
|
||||
|
||||
Score score() const {
|
||||
Score score() const
|
||||
{
|
||||
Score r = 0;
|
||||
unsigned idx = 1;
|
||||
for (auto it = cards_.rbegin(); it != cards_.rend(); ++it) {
|
||||
@@ -45,7 +48,8 @@ struct Player {
|
||||
return r;
|
||||
}
|
||||
|
||||
Hash hash() const {
|
||||
Hash hash() const
|
||||
{
|
||||
std::string r = name_;
|
||||
for (auto c : cards_) {
|
||||
assert(c > 0);
|
||||
@@ -56,21 +60,23 @@ struct Player {
|
||||
return r;
|
||||
}
|
||||
|
||||
Player(Player const &prev, Card size) : name_(prev.name_ + "-") {
|
||||
Player(Player const& prev, Card size) : name_(prev.name_ + "-")
|
||||
{
|
||||
auto it = prev.cards_.begin();
|
||||
for (Card i = 0; i < size; ++i) {
|
||||
cards_.push_back(*it++);
|
||||
}
|
||||
}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os, Player const &p);
|
||||
friend std::ostream& operator<<(std::ostream& os, Player const& p);
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
Cards cards_;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, Player const &p) {
|
||||
std::ostream& operator<<(std::ostream& os, Player const& p)
|
||||
{
|
||||
os << p.name_;
|
||||
for (auto c : p.cards_) {
|
||||
os << " " << c;
|
||||
@@ -79,7 +85,8 @@ std::ostream &operator<<(std::ostream &os, Player const &p) {
|
||||
}
|
||||
|
||||
// False = p1 wins, true = p2 wins.
|
||||
bool play_game(Player &p1, Player &p2) {
|
||||
bool play_game(Player& p1, Player& p2)
|
||||
{
|
||||
std::set<Hash> hashes;
|
||||
|
||||
while (!p1.empty() && !p2.empty()) {
|
||||
@@ -100,17 +107,21 @@ bool play_game(Player &p1, Player &p2) {
|
||||
if (!result) {
|
||||
p1.push_back(c1);
|
||||
p1.push_back(c2);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
p2.push_back(c2);
|
||||
p2.push_back(c1);
|
||||
}
|
||||
} else if (c1 > c2) {
|
||||
}
|
||||
else if (c1 > c2) {
|
||||
p1.push_back(c1);
|
||||
p1.push_back(c2);
|
||||
} else if (c1 < c2) {
|
||||
}
|
||||
else if (c1 < c2) {
|
||||
p2.push_back(c2);
|
||||
p2.push_back(c1);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@@ -118,7 +129,8 @@ bool play_game(Player &p1, Player &p2) {
|
||||
return p1.empty();
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
Player player1(std::cin);
|
||||
Player player2(std::cin);
|
||||
|
||||
|
Reference in New Issue
Block a user