feat(game): add operator< for Card

This commit is contained in:
Kieran Kihn
2025-11-16 13:23:41 +08:00
parent c8ff2dfb16
commit efb80c3b40
2 changed files with 12 additions and 0 deletions

View File

@@ -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_;
}
}

View File

@@ -81,6 +81,11 @@ namespace UNO::GAME {
* @return 卡牌对应的显示字符串
*/
[[nodiscard]] std::string toString() const;
/**
* 比较运算符,用于排序
*/
bool operator<(const Card &other) const;
};
} // namespace UNO::GAME