boardTable.cc
Go to the documentation of this file.
00001 /* directionTable.cc
00002  */
00003 #include "osl/boardTable.h"
00004 #include "osl/directionTraits.h"
00005 
00006 template <osl::Direction Dir>
00007 void osl::BoardTable::setDirections(){
00008   const int blackDx=DirectionTraits<Dir>::blackDx;
00009   const int blackDy=DirectionTraits<Dir>::blackDy;
00010   Offset offset=Offset(blackDx,blackDy);
00011 #ifndef MINIMAL
00012   space_counts[Offset32Wide(0,0).index()]=0;
00013 #endif
00014   for(int i=1;i<=8;i++){
00015     int dx=i*blackDx;
00016     int dy=i*blackDy;
00017     Offset32 offset32(dx,dy);
00018     directions[offset32.index()]=Dir;
00019     short_offsets[offset32.index()]=offset;
00020     short_offsets_not_knight[offset32.index()]=offset;
00021     short8Dir[Offset(dx,dy).intValue()-Offset::ONBOARD_OFFSET_MIN]=
00022       longToShort(Dir);
00023     short8Offset[Offset(dx,dy).intValue()-Offset::ONBOARD_OFFSET_MIN]=
00024       offset.intValue();
00025   }
00026 #ifndef MINIMAL
00027   for(int i=1;i<=10;i++){
00028     int dx=i*blackDx;
00029     int dy=i*blackDy;
00030     Offset32Wide offset32w(dx,dy);
00031     space_counts[offset32w.index()]=i-1;
00032   }
00033 #endif
00034 }
00035 template <osl::Direction Dir>
00036 void osl::BoardTable::setKnightDirections(){
00037   int dx=DirectionTraits<Dir>::blackDx;
00038   int dy=DirectionTraits<Dir>::blackDy;
00039   Offset32 offset32=Offset32(dx,dy);
00040   Offset offset=Offset(dx,dy);
00041   short_offsets[offset32.index()]=offset;
00042   short_offsets[(-offset32).index()]= -offset;
00043 }
00044 
00045 void osl::BoardTable::init(){
00046   short8Dir.fill(DIRECTION_INVALID_VALUE);
00047   short8Offset.fill();
00048   directions.fill();
00049   short_offsets_not_knight.fill();
00050 #ifndef MINIMAL
00051   space_counts.fill(-1);
00052 #endif
00053   setDirections<LONG_UL>();
00054   setDirections<LONG_U>();
00055   setDirections<LONG_UR>();
00056   setDirections<LONG_L>();
00057   setDirections<LONG_R>();
00058   setDirections<LONG_DL>();
00059   setDirections<LONG_D>();
00060   setDirections<LONG_DR>();
00061   setKnightDirections<UUL>();
00062   setKnightDirections<UUR>();
00063 }
00064 
00065 osl::BoardTable::BoardTable(){
00066   init();
00067   assert(! getOffset(BLACK, UL).zero());
00068 }
00069 
00070 /* ------------------------------------------------------------------------- */
00071 // ;;; Local Variables:
00072 // ;;; mode:c++
00073 // ;;; c-basic-offset:2
00074 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines