1 /********************************************************************** 2 * 3 * FreeDoko a Doppelkopf-Game 4 * 5 * Copyright (C) 2001 – 2018 by Diether Knof and Borg Enders 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation; either version 2 of 10 * the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * You can find this license in the file 'gpl.txt'. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21 * MA 02111-1307 USA 22 * 23 * Contact: 24 * Diether Knof dknof@posteo.de 25 * 26 **********************************************************************/ 27 28 #pragma once 29 30 #include "../basetypes.h" 31 32 class HandCard; 33 class Game; 34 35 /** Class for a card 36 **/ 37 class Card { 38 public: 39 static Card const empty; 40 static Card const unknown; 41 42 static Card const fox; 43 static Card const dulle; 44 static Card const charlie; 45 46 static Card const club_ace; 47 static Card const spade_ace; 48 static Card const heart_ace; 49 static Card const diamond_ace; 50 static Card const club_ten; 51 static Card const spade_ten; 52 static Card const heart_ten; 53 static Card const diamond_ten; 54 static Card const club_king; 55 static Card const spade_king; 56 static Card const heart_king; 57 static Card const diamond_king; 58 static Card const club_queen; 59 static Card const spade_queen; 60 static Card const heart_queen; 61 static Card const diamond_queen; 62 static Card const club_jack; 63 static Card const spade_jack; 64 static Card const heart_jack; 65 static Card const diamond_jack; 66 static Card const club_nine; 67 static Card const spade_nine; 68 static Card const heart_nine; 69 static Card const diamond_nine; 70 71 static unsigned constexpr number_of_colors = 4u; 72 static unsigned constexpr number_of_tcolors = number_of_colors + 1; 73 static unsigned constexpr number_of_values = 6u; 74 static unsigned constexpr number_of_cards = number_of_colors * number_of_values; 75 76 enum Value : int8_t { 77 nine = 0, 78 jack = 2, 79 queen = 3, 80 king = 4, 81 ten = 10, 82 ace = 11, 83 nocardvalue = 100, // for simpler error-tracking 84 unknowncardvalue = 101, // for simpler error-tracking 85 maxcardvalue = unknowncardvalue 86 }; // enum Value 87 88 enum TColor : int8_t { 89 diamond = 0, 90 heart, 91 spade, 92 club, 93 trump, 94 nocardcolor = 100, // for simpler error-tracking 95 unknowncardcolor = 101, // for simpler error-tracking 96 maxcardcolor = unknowncardcolor 97 }; // enum TColor 98 using Color = TColor; 99 100 // converts the string in a value 101 static Value value(string const& value); 102 // converts the string in a color 103 static Color color(string const& color); 104 105 public: 106 107 constexpr Card() noexcept = default; 108 constexpr Card(Card const& c) noexcept = default; 109 constexpr Card& operator=(Card const& card) noexcept = default; Card(Color c,Value v)110 constexpr Card(Color c, Value v) noexcept : 111 color_(c), value_(v) 112 { } 113 Card(string const& name); 114 115 //virtual ~Card() = default; 116 117 istream& read(istream& istr); 118 color()119 constexpr Color color() const noexcept 120 { return color_; } value()121 constexpr Value value() const noexcept 122 { return value_; } 123 is_empty()124 constexpr bool is_empty() const noexcept 125 { return color_ == nocardcolor || value_ == nocardvalue; } 126 constexpr explicit operator bool() const noexcept 127 { return !this->is_empty(); } is_unknown()128 constexpr bool is_unknown() const noexcept 129 { return color_ == unknowncardcolor || value_ == unknowncardvalue; } 130 131 // convert to an integer (between 1 and 24) 132 int to_int() const noexcept; 133 points()134 constexpr unsigned points() const noexcept 135 { return static_cast<unsigned>(value_); } 136 137 Card::TColor tcolor(Game const& game) const; 138 bool istrump(Game const& game) const; 139 bool istrump(GameType gametype, bool dullen) const; 140 bool isdulle(Game const& game) const; 141 bool isdulle(GameType gametype, bool dullen) const; 142 143 bool less(HandCard const& card) const; 144 145 constexpr bool operator==(Card const& rhs) const noexcept 146 { return color_ == rhs.color_ && value_ == rhs.value_; } 147 constexpr bool operator!=(Card const& rhs) const noexcept 148 { return color_ != rhs.color_ || value_ != rhs.value_; } 149 constexpr bool operator<(Card const& rhs) const noexcept 150 { return (color_ < rhs.color_ || (color_ == rhs.color_ && value_ < rhs.value_)); } 151 private: 152 Color color_ = nocardcolor; 153 Value value_ = nocardvalue; 154 }; // class Card 155 156 // whether the marriage is determined by a 'tcolor'-trick 157 bool is_selector(Card::TColor tcolor, MarriageSelector marriage_selector); 158 159 GameType solo(Card::Value picture) noexcept; 160 GameType solo(Card::Value picture1, Card::Value picture2) noexcept; 161 GameType solo(Card::Color color) noexcept; 162 163 string to_string(Card::Value value) noexcept; 164 string to_string(Card::TColor tcolor) noexcept; 165 string to_string(Card const& card) noexcept; 166 string gettext(Card::Value value); 167 string gettext(Card::Color color); 168 string gettext(Card const& card); 169 170 ostream& operator<<(ostream& ostr, Card::Value value); 171 istream& operator>>(istream& istr, Card::Value& value); 172 ostream& operator<<(ostream& ostr, Card::TColor tcolor); 173 istream& operator>>(istream& istr, Card::Color& color); 174 ostream& operator<<(ostream& ostr, Card const& card); 175 istream& operator>>(istream& istr, Card& card); 176