00001 /* offset32.h 00002 */ 00003 #ifndef OSL_OFFSET32_H 00004 #define OSL_OFFSET32_H 00005 00006 #include "osl/basic_type.h" 00007 00008 namespace osl 00009 { 00015 template <int Width, int Width2> 00016 class Offset32Base 00017 { 00018 enum { 00019 MIN = -(Width*32+Width), 00020 MAX = (Width*32+Width), 00021 }; 00022 public: 00023 static const unsigned int SIZE=(MAX-MIN+1); 00024 private: 00025 int offset32; 00026 explicit Offset32Base(int o) : offset32(o) 00027 { 00028 } 00029 public: 00030 Offset32Base(Square to, Square from) 00031 : offset32(to.indexForOffset32()-from.indexForOffset32()) 00032 { 00033 assert((to.x()-from.x() >= -Width) && (to.x()-from.x() <= Width) 00034 && (to.y()-from.y() >= -Width) && (to.y()-from.y() <= Width)); 00035 assert(MIN<=offset32 && offset32<=MAX); 00036 } 00037 Offset32Base(int dx,int dy) : offset32(dx*32+dy) { 00038 assert(-Width2<=dx && dx<=Width2 && -Width2<=dy && dy<=Width2); 00039 } 00040 unsigned int index() const 00041 { 00042 return offset32 - MIN; 00043 } 00044 bool isValid() const 00045 { 00046 return MIN <=offset32 && offset32 <= MAX; 00047 } 00051 template<Player P> 00052 const Offset32Base blackOffset32() const { 00053 return P == BLACK ? *this : Offset32Base(-offset32); 00054 } 00055 const Offset32Base operator-() const { return Offset32Base(-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(Offset32Base offset32); 00060 int dy(Offset32Base offset32); 00061 }; 00062 00063 typedef Offset32Base<8,9> Offset32; 00064 typedef Offset32Base<10,10> Offset32Wide; 00065 } // namespace osl 00066 00067 00068 #endif /* OSL_OFFSET32_H */ 00069 // ;;; Local Variables: 00070 // ;;; mode:c++ 00071 // ;;; c-basic-offset:2 00072 // ;;; End: