From efb80c3b40da06bc605b906ec0032614498d29a9 Mon Sep 17 00:00:00 2001 From: Kieran Kihn <114803508+kierankihn@users.noreply.github.com> Date: Sun, 16 Nov 2025 13:23:41 +0800 Subject: [PATCH] feat(game): add operator< for `Card` --- src/game/Card.cpp | 7 +++++++ src/game/Card.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/game/Card.cpp b/src/game/Card.cpp index 3fc2864..9abf7a7 100644 --- a/src/game/Card.cpp +++ b/src/game/Card.cpp @@ -68,4 +68,11 @@ namespace UNO::GAME { } return std::format("{} {}", this->colorToString(), this->typeToString()); } + + bool Card::operator<(const Card &other) const { + if (this->color_ != other.color_) { + return this->color_ < other.color_; + } + return this->type_ < other.type_; + } } diff --git a/src/game/Card.h b/src/game/Card.h index 9a3f28a..3082265 100644 --- a/src/game/Card.h +++ b/src/game/Card.h @@ -81,6 +81,11 @@ namespace UNO::GAME { * @return 卡牌对应的显示字符串 */ [[nodiscard]] std::string toString() const; + + /** + * 比较运算符,用于排序 + */ + bool operator<(const Card &other) const; }; } // namespace UNO::GAME