TheChess

model/EloPlayer.hpp

00001 /*
00002  * thechess, chess game web application written in C++ and based on Wt
00003  * Copyright (C) 2010 Boris Nagaev
00004  *
00005  * thechess is licensed under the GNU GPL Version 2.
00006  * Other versions of the GPL do not apply.
00007  * See the LICENSE file for terms of use.
00008  */
00009 
00010 #ifndef THECHESS_MODEL_ELOPLAYER_HPP_
00011 #define THECHESS_MODEL_ELOPLAYER_HPP_
00012 
00013 #include <vector>
00014 
00015 namespace thechess {
00016 namespace model {
00017 class EloPlayer;
00018 typedef std::vector<EloPlayer*> EloPlayers;
00019 }
00020 }
00021 
00022 #include <Wt/Dbo/Dbo>
00023 #include <Wt/Dbo/ptr>
00024 namespace dbo = Wt::Dbo;
00025 
00026 namespace thechess {
00027 namespace model {
00028 
00029 class EloPlayer {
00030 public:
00031     EloPlayer();
00032     EloPlayer(bool);
00033 
00034     const int& elo() const {
00035         return elo_;
00036     }
00037     const int& all() const {
00038         return all_;
00039     }
00040     const int& wins() const {
00041         return wins_;
00042     }
00043     const int& fails() const {
00044         return fails_;
00045     }
00046     int draws() const;
00047 
00048     float K() const;
00049     float Q() const;
00050     float E(const EloPlayer* other) const;
00051     float E(float q_sum) const;
00052 
00053     void win(EloPlayer* loser);
00054     void draw(EloPlayer* other);
00055     static void multiple(const EloPlayers& winners, const EloPlayers& losers);
00056 
00057 private:
00058     int elo_;
00059     int all_;
00060     int wins_;
00061     int fails_;
00062 
00063     void apply_result_(float q_sum, float S);
00064 };
00065 
00066 }
00067 }
00068 
00069 namespace Wt {
00070 namespace Dbo {
00071 
00072 template<class Action>
00073 void field(Action& a, thechess::model::EloPlayer& p, const std::string& name) {
00074     field(a, const_cast<int&>(p.elo()), name + "_elo");
00075     field(a, const_cast<int&>(p.all()), name + "_all");
00076     field(a, const_cast<int&>(p.wins()), name + "_wins");
00077     field(a, const_cast<int&>(p.fails()), name + "_fails");
00078 }
00079 
00080 }
00081 }
00082 
00083 
00084 #endif
00085 
 All Classes Functions Enumerations Enumerator