00001 #ifndef _PLAYER_H
00002 #define _PLAYER_H
00003 #include <cassert>
00004 #include <iosfwd>
00005 namespace osl{
00006 enum Player{
00007 BLACK=0,
00008 WHITE= -1
00009 };
00010
00011 inline Player alt(Player player){
00012 return static_cast<Player>(-1-static_cast<int>(player));
00013 }
00014 inline void changeTurn(Player &player){
00015 player= alt(player);
00016 }
00017 inline int playerToIndex(Player player){
00018 return -static_cast<int>(player);
00019 }
00020 inline int playerToMul(Player player){
00021 int ret=1+(static_cast<int>(player)<<1);
00022 assert(ret==1 || ret== -1);
00023 return ret;
00024 }
00025 inline int playerToMask(Player player){
00026 return static_cast<int>(player);
00027 }
00028
00032 bool isValid(Player player);
00033
00034 template<Player P>
00035 struct PlayerTraits;
00036
00037 template<>
00038 struct PlayerTraits<BLACK>{
00039 static const int offsetMul=1;
00040 static const int index=0;
00041 static const int mask=0;
00042 static const Player opponent=WHITE;
00043 };
00044
00045 template<>
00046 struct PlayerTraits<WHITE>{
00047 static const int offsetMul=-1;
00048 static const int index=1;
00049 static const int mask= -1;
00050 static const Player opponent=BLACK;
00051 };
00052
00053 std::ostream& operator<<(std::ostream& os,Player player);
00054 }
00055 #endif
00056
00057
00058
00059