00001 #ifndef _PLAYER_H
00002 #define _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 void changeTurn(Player &player){
00016 player= alt(player);
00017 }
00018 inline int playerToIndex(Player player){
00019 return -static_cast<int>(player);
00020 }
00021 inline Player indexToPlayer(int n) {
00022 assert(n == 0 || n == 1);
00023 return static_cast<Player>(-n);
00024 }
00025 inline int playerToMul(Player player){
00026 int ret=1+(static_cast<int>(player)<<1);
00027 assert(ret==1 || ret== -1);
00028 return ret;
00029 }
00030 inline int playerToMask(Player player){
00031 return static_cast<int>(player);
00032 }
00033
00034
00035
00036 int operator+(Player, int); int operator+(int, Player);
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
00044 bool isValid(Player player);
00045
00046 template<Player P>
00047 struct PlayerTraits;
00048
00049 template<>
00050 struct PlayerTraits<BLACK>{
00051 static const int offsetMul=1;
00052 static const int index=0;
00053 static const int mask=0;
00054 static const Player opponent=WHITE;
00055 };
00056
00057 template<>
00058 struct PlayerTraits<WHITE>{
00059 static const int offsetMul=-1;
00060 static const int index=1;
00061 static const int mask= -1;
00062 static const Player opponent=BLACK;
00063 };
00064
00065 std::ostream& operator<<(std::ostream& os,Player player);
00066 }
00067 #endif
00068
00069
00070
00071