player.h
Go to the documentation of this file.
00001 #ifndef OSL_PLAYER_H
00002 #define OSL_PLAYER_H
00003 #include <boost/static_assert.hpp>
00004 #include <cassert>
00005 #include <iosfwd>
00006 namespace osl{
00007   enum Player{
00008     BLACK=0,
00009     WHITE= -1
00010   };
00011   
00012   inline Player alt(Player player){
00013     return static_cast<Player>(-1-static_cast<int>(player));
00014   }
00015   inline int playerToIndex(Player player){
00016     return -static_cast<int>(player);
00017   }
00018   inline Player indexToPlayer(int n) {
00019     assert(n == 0 || n == 1);
00020     return static_cast<Player>(-n);
00021   }
00022   inline int playerToMul(Player player){
00023     int ret=1+(static_cast<int>(player)<<1);
00024     assert(ret==1 || ret== -1);
00025     return ret;
00026   }
00027   inline int playerToMask(Player player){
00028     return static_cast<int>(player);
00029   }
00030 
00031   // These codes are intentionally DECLARED and NOT IMPLEMENTED.
00032   // you will get link error here if you write code such as "value += v * piece.owner() == BLACK ? 1.0 : -1.0;"
00033   int operator+(Player, int);   int operator+(int, Player);     
00034   int operator-(Player, int);   int operator-(int, Player);     
00035   int operator*(Player, int);   int operator*(int, Player);     
00036   int operator/(Player, int);   int operator/(int, Player);     
00037   
00041   bool isValid(Player player);
00042     
00043   template<Player P>
00044   struct PlayerTraits;
00045   
00046   template<>
00047   struct PlayerTraits<BLACK>{
00048     static const int offsetMul=1;
00049     static const int index=0;
00050     static const int mask=0;
00051     static const Player opponent=WHITE;
00052   };
00053   
00054   template<>
00055   struct PlayerTraits<WHITE>{
00056     static const int offsetMul=-1;
00057     static const int index=1;
00058     static const int mask= -1;
00059     static const Player opponent=BLACK;
00060   };
00061   
00062   std::ostream& operator<<(std::ostream& os,Player player);
00063 }
00064 #endif /* OSL_PLAYER_H */
00065 // ;;; Local Variables:
00066 // ;;; mode:c++
00067 // ;;; c-basic-offset:2
00068 // ;;; coding:utf-8
00069 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines