diff options
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/game/card.cpp | 28 | ||||
| -rw-r--r-- | src/main/game/card.h | 4 | ||||
| -rw-r--r-- | src/main/game/pile.cpp | 16 | ||||
| -rw-r--r-- | src/main/game/pile.h | 13 |
4 files changed, 57 insertions, 4 deletions
diff --git a/src/main/game/card.cpp b/src/main/game/card.cpp index 5189171..25a981f 100644 --- a/src/main/game/card.cpp +++ b/src/main/game/card.cpp @@ -82,3 +82,31 @@ bool operator==(const card& l, const card& r) { bool operator!=(const card& l, const card& r) { return !(l == r); } + +bool operator<(const card& l, const card& r) { + if (l.get_rank() == r.get_rank()) + return l.get_suit() < r.get_suit(); + else + return l.get_rank() < r.get_rank(); +} + +bool operator>(const card& l, const card& r) { + if (l.get_rank() == r.get_rank()) + return l.get_suit() > r.get_suit(); + else + return l.get_rank() > r.get_rank(); +} + +bool operator<=(const card& l, const card& r) { + if (l.get_rank() == r.get_rank()) + return l.get_suit() <= r.get_suit(); + else + return l.get_rank() <= r.get_rank(); +} + +bool operator>=(const card& l, const card& r) { + if (l.get_rank() == r.get_rank()) + return l.get_suit() >= r.get_suit(); + else + return l.get_rank() >= r.get_rank(); +} diff --git a/src/main/game/card.h b/src/main/game/card.h index aec6a88..318cd12 100644 --- a/src/main/game/card.h +++ b/src/main/game/card.h @@ -48,6 +48,10 @@ private: bool operator==(const card&, const card&); bool operator!=(const card&, const card&); +bool operator<(const card&, const card&); +bool operator>(const card&, const card&); +bool operator<=(const card&, const card&); +bool operator>=(const card&, const card&); #endif //SOLITAIRE_PIP_CARD_H diff --git a/src/main/game/pile.cpp b/src/main/game/pile.cpp index 21eddc0..6d52335 100644 --- a/src/main/game/pile.cpp +++ b/src/main/game/pile.cpp @@ -50,3 +50,19 @@ card pile::take() { bool operator==(const pile& a, const pile& b) { return a.pile_vec == b.pile_vec; } + +bool operator<(const pile& a, const pile& b) { + return a.pile_vec < b.pile_vec; +} + +bool operator>(const pile& a, const pile& b) { + return a.pile_vec > b.pile_vec; +} + +bool operator<=(const pile& a, const pile& b) { + return a.pile_vec <= b.pile_vec; +} + +bool operator>=(const pile& a, const pile& b) { + return a.pile_vec >= b.pile_vec; +} diff --git a/src/main/game/pile.h b/src/main/game/pile.h index 2bf2d5b..4256b02 100644 --- a/src/main/game/pile.h +++ b/src/main/game/pile.h @@ -13,6 +13,7 @@ class pile { friend class hasher; + friend class game_state; public: typedef uint8_t size_type; @@ -25,16 +26,20 @@ public: bool empty() const; size_type size() const; - // Modify - void place(card); - card take(); - // Indexes the vector, with the top card as index 0 card& operator[] (size_type); card operator[] (size_type) const; friend bool operator==(const pile&, const pile&); + friend bool operator<(const pile&, const pile&); + friend bool operator>(const pile&, const pile&); + friend bool operator<=(const pile&, const pile&); + friend bool operator>=(const pile&, const pile&); private: + // Modify + void place(card); + card take(); + // Underlying vector std::vector<card> pile_vec; }; |
