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