boardBitMask.cc
Go to the documentation of this file.
00001 #include "osl/effect/boardBitMask.h"
00002 #include "osl/ptype.h"
00003 #include "osl/ptypeTable.h"
00004 #include <iostream>
00005 
00006 namespace osl
00007 {
00008 namespace effect
00009 {
00010 
00011   std::ostream& operator<<(std::ostream& os,BoardBitMask const& boardBitMask){
00012     os << "[";
00013     for(int i=15;i>=0;i--){
00014       unsigned char uc=boardBitMask.bMask[i];
00015       for(int j=7;j>=0;j--){
00016         if((uc&(1<<j))!=0) os << "1";
00017         else os<<"0";
00018       }
00019       os<<" ";
00020     }
00021     return os << "]";
00022   }
00023   
00024 
00025   void BoardBitMaskTable::initMaskOfSquare(){
00026     for(int i=0;i<Square::SIZE;i++){
00027       maskOfSquare[i].clearAll();
00028     }
00029     for(int y=1;y<=9;y++)
00030       for(int x=1;x<=9;x++){
00031         Square pos(x,y);
00032         maskOfSquare[pos.index()].setBit(BoardBitMask::positionToOffset(pos));
00033       }
00034   }
00035 
00036   static void setBetweenMask(BoardBitMask& mask,Square from,Square to,
00037                              Ptype ptype){
00038     const EffectContent effect=Ptype_Table.getEffect(newPtypeO(BLACK,ptype),Offset32(to,from));
00039     if(!effect.hasBlockableEffect()) return;
00040     const Offset offset=effect.offset();
00041     mask.clearAll();
00042     for(Square pos=from+offset;pos!=to;pos+=offset){
00043       mask.setBit(pos);
00044     }
00045   }
00046   void BoardBitMaskTable::initBetweenMask(){
00047     for(int j=0;j<Square::SIZE;j++){
00048       for(int i=0;i<Square::SIZE;i++){
00049         rookBetweenMask[i][j].setAll();
00050         lanceBetweenMask[i][j].setAll();
00051         bishopBetweenMask[i][j].setAll();
00052       }
00053     }
00054     for(int y1=1;y1<=9;y1++)
00055       for(int x1=1;x1<=9;x1++){
00056         Square from(x1,y1);
00057         for(int y2=1;y2<=9;y2++)
00058           for(int x2=1;x2<=9;x2++){
00059             Square to(x2,y2);
00063             setBetweenMask(lanceBetweenMask[from.index()][to.index()],from,to,LANCE);
00064             setBetweenMask(bishopBetweenMask[from.index()][to.index()],from,to,BISHOP);
00065             setBetweenMask(rookBetweenMask[from.index()][to.index()],from,to,ROOK);
00066           }
00067       }
00068   }
00069 
00070   BoardBitMaskTable::BoardBitMaskTable(){
00071     initMaskOfSquare();
00072     initBetweenMask();
00073   }
00074 } // namespace effect
00075 } // namespace osl
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines