00001 /* offset32.h 00002 */ 00003 #ifndef _OFFSET32_H 00004 #define _OFFSET32_H 00005 00006 #include "osl/misc/loki.h" 00007 #include "osl/position.h" 00008 00009 namespace osl 00010 { 00016 class Offset32 00017 { 00018 enum { 00019 MIN = -(8*32+8), 00020 MAX = (8*32+8), 00021 }; 00022 public: 00023 static const unsigned int SIZE=(Offset32::MAX-Offset32::MIN+1); 00024 private: 00025 int offset32; 00026 explicit Offset32(int o) : offset32(o) 00027 { 00028 } 00029 public: 00030 Offset32(Position to, Position from) 00031 : offset32(to.indexForOffset32()-from.indexForOffset32()) 00032 { 00033 assert((to.x()-from.x() >= -8) && (to.x()-from.x() <= 8) 00034 && (to.y()-from.y() >= -8) && (to.y()-from.y() <= 8)); 00035 assert(Offset32::MIN<=offset32 && offset32<=Offset32::MAX); 00036 } 00037 Offset32(int dx,int dy) : offset32(dx*32+dy) { 00038 assert(-9<=dx && dx<=9 && -9<=dy && dy<=9); 00039 } 00040 unsigned int index() const 00041 { 00042 return offset32 - Offset32::MIN; 00043 } 00044 bool isValid() const; 00045 private: 00046 const Offset32 blackOffset32(Int2Type<BLACK>) const { return *this; } 00047 const Offset32 blackOffset32(Int2Type<WHITE>) const { return Offset32(-offset32); } 00048 public: 00052 template<Player P> 00053 const Offset32 blackOffset32() const { return blackOffset32(Int2Type<P>()); } 00054 00055 const Offset32 operator-() const { return Offset32(-offset32); } 00056 private: 00057 // these functions are *intentionally* unimplemented for the moment. 00058 // don't forget the fact that x or y can be negative. 00059 int dx(Offset32 offset32); 00060 int dy(Offset32 offset32); 00061 }; 00062 } // namespace osl 00063 00064 00065 #endif /* _OFFSET32_H */ 00066 // ;;; Local Variables: 00067 // ;;; mode:c++ 00068 // ;;; c-basic-offset:2 00069 // ;;; End: