effectedNumTable.cc
Go to the documentation of this file.
00001 /* effectedNumTable.cc
00002  */
00003 #include "osl/effect/effectedNumTable.h"
00004 #include "osl/ptypeTable.h"
00005 #include "osl/boardTable.h"
00006 
00007 void
00008 osl::effect::EffectedNumTable::clear()
00009 {
00010   for(int i=0;i<40;i++) contents[i].clear();
00011 }
00012 
00013 osl::effect::EffectedNumTable::EffectedNumTable(SimpleState const& state)
00014 {
00015   clear();
00016   for(int num=32;num<=39;num++){
00017     osl::Piece p=state.pieceOf(num);
00018     if(!p.isOnBoard()) continue;
00019     int moveMask=Ptype_Table.getMoveMask(p.ptype());
00020     for(int i=0;i<8;i++){
00021       Direction d=static_cast<Direction>(i);
00022       if(p.owner()==WHITE) d=inverse(d);
00023       Direction longD=shortToLong(d);
00024       if((moveMask&dirToMask(longD))==0) continue;
00025       Offset o=Board_Table.getOffsetForBlack(static_cast<Direction>(i));
00026       Square pos=p.square()+o;
00027       Piece p1;
00028       for(;(p1=state.pieceAt(pos)).isEmpty();pos+=o) ;
00029       if(pos.isEdge()) continue;
00030       int num1=p1.number();
00031       contents[num1][static_cast<Direction>(i)]=num1;
00032     }
00033   }
00034 }
00035 
00036 std::ostream& osl::effect::operator<<(std::ostream& os,osl::EffectedNumTable const& et)
00037 {
00038   os << "[\n";
00039   for(int num=0;num<=39;num++){
00040     os << " [";
00041     for(int d=0;d<7;d++) os << et[num][static_cast<Direction>(d)] << ",";
00042     os << et[num][static_cast<Direction>(7)] << "],\n";
00043   }
00044   return os <<  "]\n";
00045 }
00046 bool osl::effect::operator==(EffectedNumTable const& e1, EffectedNumTable const& e2)
00047 {
00048   for(int i=0;i<8;i++){
00049     for(int num=0;num<=39;num++){
00050       if(e1[num][static_cast<Direction>(i)]!=e2[num][static_cast<Direction>(i)]) return false;
00051     }
00052   }
00053   return true;
00054 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines