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 playerToSign(Player player)
00028 {
00029 return playerToMul(player);
00030 }
00031 inline int playerToMask(Player player){
00032 return static_cast<int>(player);
00033 }
00034
00035
00036
00037 int operator+(Player, int); int operator+(int, Player);
00038 int operator-(Player, int); int operator-(int, Player);
00039 int operator*(Player, int); int operator*(int, Player);
00040 int operator/(Player, int); int operator/(int, Player);
00041
00045 bool isValid(Player player);
00046
00047 template<Player P>
00048 struct PlayerTraits;
00049
00050 template<>
00051 struct PlayerTraits<BLACK>{
00052 static const int offsetMul=1;
00053 static const int index=0;
00054 static const int mask=0;
00055 static const Player opponent=WHITE;
00056 };
00057
00058 template<>
00059 struct PlayerTraits<WHITE>{
00060 static const int offsetMul=-1;
00061 static const int index=1;
00062 static const int mask= -1;
00063 static const Player opponent=BLACK;
00064 };
00065
00066 std::ostream& operator<<(std::ostream& os,Player player);
00067 }
00068 #endif
00069
00070
00071
00072
00073