squareCompressor.h
Go to the documentation of this file.
00001 /* squareCompressor.h
00002  */
00003 #ifndef OSL_POSITIONCOMPRESSOR_H
00004 #define OSL_POSITIONCOMPRESSOR_H
00005 
00006 #include "osl/square.h"
00007 #include "osl/misc/carray.h"
00008 namespace osl
00009 {
00010 
00015   struct SquareCompressor
00016   {
00017   private:
00019     static CArray<signed char, Square::SIZE> positionToIndex;
00020   public:
00021     class Initializer;
00022     friend class Initializer;
00023 
00024     static int compress(Square pos)
00025     {
00026       const int result = positionToIndex[pos.index()];
00027       assert(result >= 0);
00028       return result;
00029     }
00030     static Square
00031 #ifdef __GNUC__
00032 __attribute__ ((noinline))
00033 #endif
00034       melt(int index)
00035     {
00036       assert(0 <= index);
00037       assert(index < 82);
00038       if (index == 0)
00039         return Square::STAND();
00040       --index;
00041       return Square(index/9+1, index%9+1);
00042     }
00043   };
00044 
00045 } // namespace osl
00046 
00047 #endif /* OSL_POSITIONCOMPRESSOR_H */
00048 // ;;; Local Variables:
00049 // ;;; mode:c++
00050 // ;;; c-basic-offset:2
00051 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines