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 "../game/specialpoint.h" 31 #include "player.h" 32 class GameSummary; 33 34 /// [T]otal[L]ost[W]on count 35 class TLWcount { 36 public: 37 TLWcount() = default; 38 ~TLWcount() = default; 39 write(ostream & ostr)40 ostream& write(ostream& ostr) const 41 { 42 ostr << this->total() << '\t' 43 << this->won() << '\t' 44 << this->lost(); 45 return ostr; 46 } read(istream & istr)47 istream& read(istream& istr) 48 { 49 istr >> this->total_ 50 >> this->won_ 51 >> this->lost_; 52 return istr; 53 } 54 hasLost()55 void hasLost() { total_++; lost_++; }; hasWon()56 void hasWon() { total_++; won_++; }; 57 total()58 unsigned long long total() const { return total_; } lost()59 unsigned long long lost() const { return lost_; } won()60 unsigned long long won() const { return won_; } 61 clear()62 void clear() 63 { 64 this->total_ = 0; 65 this->lost_ = 0; 66 this->won_ = 0; 67 } 68 69 TLWcount& operator+=(TLWcount const& tlwcount) 70 { 71 this->total_ += tlwcount.total(); 72 this->lost_ += tlwcount.lost(); 73 this->won_ += tlwcount.won(); 74 return *this; 75 } 76 77 private: 78 unsigned long long total_ = 0; 79 unsigned long long lost_ = 0; 80 unsigned long long won_ = 0; 81 }; // class TLWcount 82 83 ostream& operator<<(ostream& ostr, TLWcount const& tlwcount); 84 istream& operator>>(istream& istr, TLWcount& tlwcount); 85 86 87 class Ranking { 88 public: value_(d)89 Ranking(double const d = 0) : value_(d) {}; 90 Ranking& operator=(Ranking const& r) = default; 91 ~Ranking() = default; 92 write(ostream & ostr)93 ostream& write(ostream& ostr) const 94 { 95 ostr << this->value(); 96 return ostr; 97 } read(istream & istr)98 istream& read(istream& istr) 99 { 100 istr >> this->value_; 101 return istr; 102 } 103 add(Ranking const & r)104 void add(Ranking const& r) 105 { 106 this->value_ = ( 0.9 * this->value_ + r.value_ ) / 1.9; 107 } 108 value()109 double value() const { return value_; }; 110 111 112 Ranking& operator+=(Ranking const& b) 113 { 114 this->add( b ); 115 return *this; 116 }; 117 clear()118 void clear() 119 { 120 this->value_ = 0; 121 } 122 123 private: 124 double value_ = 0; 125 }; // class Ranking 126 127 ostream& operator<<(ostream& ostr, Ranking const& ranking); 128 istream& operator>>(istream& istr, Ranking& ranking); 129 130 131 class PlayersDb { 132 public: 133 PlayersDb() = default; 134 explicit PlayersDb(istream& istr); 135 PlayersDb( PlayersDb const& p ) = default; 136 137 virtual ~PlayersDb() = default; 138 139 virtual ostream& write(ostream& ostr) const; 140 istream& read(istream& istr); 141 protected: 142 virtual bool read_group(string const& name, istream& istr); 143 private: 144 void read_group_games(istream& istr); 145 void read_group_specialpoints(istream& istr); 146 public: 147 148 virtual void evaluate( const Player& p, GameSummary const& game_summary ); 149 150 /// number of each played game lost and won games(GameType const i)151 TLWcount const& games(GameType const i) const 152 { 153 return games_[i]; 154 } 155 156 /// number of special points made or given away specialpoints(Specialpoint::Type const i)157 TLWcount const& specialpoints(Specialpoint::Type const i) const 158 { 159 return specialpoints_[i]; 160 } 161 games_all()162 TLWcount const& games_all() const 163 { return this->games_all_; } 164 TLWcount games_group_marriage() const; 165 TLWcount games_group_poverty() const; 166 TLWcount games_group_solo() const; 167 TLWcount games_group_solo_color() const; 168 TLWcount games_group_solo_picture() const; 169 TLWcount games_group_solo_picture_single() const; 170 TLWcount games_group_solo_picture_double() const; 171 specialpoints_all()172 TLWcount const& specialpoints_all() const 173 { return this->specialpoints_all_; } 174 TLWcount specialpoints_group_winning() const; 175 TLWcount specialpoints_group_announcement() const; 176 177 /// average points made with each game averageGamePoints()178 double averageGamePoints() const 179 { return averageGamePoints_; } 180 181 /// average point made with trikcs in each game averageGameTrickPoints()182 double averageGameTrickPoints() const 183 { return averageGameTrickPoints_; } 184 185 virtual void clear(); 186 187 Ranking rank; 188 189 private: 190 double averageGamePoints_; 191 double averageGameTrickPoints_; 192 193 TLWcount games_all_; 194 mutable std::map<GameType, TLWcount> games_; 195 196 TLWcount specialpoints_all_; 197 mutable std::map<Specialpoint::Type, TLWcount> specialpoints_; 198 }; // class PlayersDb 199 200 ostream& operator<<(ostream& ostr, PlayersDb const& players_db); 201 istream& operator>>(istream& istr, PlayersDb& players_db); 202