ptypeProgress.cc
Go to the documentation of this file.
00001 #include "osl/progress/ptypeProgress.h"
00002 #include "osl/pieceTable.h"
00003 #include <iostream>
00004 
00005 namespace osl
00006 {
00007   namespace progress
00008   {
00010     template<Ptype T>
00011     struct PtypeProgressTraits;
00012     // 歩
00013     template<>
00014     struct PtypeProgressTraits<PAWN>{
00015       static const int val=2;
00016     };
00017     template<>
00018     struct PtypeProgressTraits<PPAWN>{
00019       static const int val=2;
00020     };
00021     //
00022     template<>
00023     struct PtypeProgressTraits<LANCE>{
00024       static const int val=5;
00025     };
00026     template<>
00027     struct PtypeProgressTraits<PLANCE>{
00028       static const int val=5;
00029     };
00030     //
00031     template<>
00032     struct PtypeProgressTraits<KNIGHT>{
00033       static const int val=5;
00034     };
00035     template<>
00036     struct PtypeProgressTraits<PKNIGHT>{
00037       static const int val=5;
00038     };
00039     //
00040     template<>
00041     struct PtypeProgressTraits<SILVER>{
00042       static const int val=7;
00043     };
00044     template<>
00045     struct PtypeProgressTraits<PSILVER>{
00046       static const int val=7;
00047     };
00048     //
00049     template<>
00050     struct PtypeProgressTraits<GOLD>{
00051       static const int val=8;
00052     };
00053     //
00054     template<>
00055     struct PtypeProgressTraits<BISHOP>{
00056       static const int val=7;
00057     };
00058     template<>
00059     struct PtypeProgressTraits<PBISHOP>{
00060       static const int val=7;
00061     };
00062     //
00063     template<>
00064     struct PtypeProgressTraits<ROOK>{
00065       static const int val=10;
00066     };
00067     template<>
00068     struct PtypeProgressTraits<PROOK>{
00069       static const int val=10;
00070     };
00071     //
00072     template<>
00073     struct PtypeProgressTraits<KING>{
00074       static const int val=15;
00075     };
00076   } // namespace progress
00077 } // namespace osl
00078 
00079 osl::progress::
00080 PtypeProgress::PtypeProgress(SimpleState const& state)
00081 {
00082   int ret=0;
00083   for (int num=0; num<Piece::SIZE; num++)
00084   {
00085     if(state.standMask(BLACK).test(num)){
00086       ret+=Ptype_Progress_Table.progress(newPtypeO(BLACK,Piece_Table.getPtypeOf(num)),
00087                                      Square::STAND());
00088     }
00089     else if(state.standMask(WHITE).test(num)){
00090       ret+=Ptype_Progress_Table.progress(newPtypeO(WHITE,Piece_Table.getPtypeOf(num)),
00091                                      Square::STAND());
00092     }
00093     else{
00094       assert(state.isOnBoard(num));
00095       const Piece p=state.pieceOf(num);
00096       ret+=Ptype_Progress_Table.progress(p.ptypeO(),p.square());
00097     }
00098   }
00099   val=ret;
00100 }
00101 
00102 osl::progress::PtypeProgressTable::PtypeProgressTable()
00103 {
00104   ptype2Val[PAWN]=PtypeProgressTraits<PAWN>::val;
00105   ptype2Val[PPAWN]=PtypeProgressTraits<PPAWN>::val;
00106   ptype2Val[LANCE]=PtypeProgressTraits<LANCE>::val;
00107   ptype2Val[PLANCE]=PtypeProgressTraits<PLANCE>::val;
00108   ptype2Val[KNIGHT]=PtypeProgressTraits<KNIGHT>::val;
00109   ptype2Val[PKNIGHT]=PtypeProgressTraits<PKNIGHT>::val;
00110   ptype2Val[SILVER]=PtypeProgressTraits<SILVER>::val;
00111   ptype2Val[PSILVER]=PtypeProgressTraits<PSILVER>::val;
00112   ptype2Val[GOLD]=PtypeProgressTraits<GOLD>::val;
00113   ptype2Val[KING]=PtypeProgressTraits<KING>::val;
00114   ptype2Val[BISHOP]=PtypeProgressTraits<BISHOP>::val;
00115   ptype2Val[PBISHOP]=PtypeProgressTraits<PBISHOP>::val;
00116   ptype2Val[ROOK]=PtypeProgressTraits<ROOK>::val;
00117   ptype2Val[PROOK]=PtypeProgressTraits<PROOK>::val;
00118   for(int i=PTYPE_MIN;i<=PTYPE_MAX;i++){
00119     Ptype ptype=static_cast<Ptype>(i);
00120     pos2Val[newPtypeO(BLACK,ptype)-PTYPEO_MIN][Square::STAND().index()]=ptype2Val[i]*yVals[5];
00121     pos2Val[newPtypeO(WHITE,ptype)-PTYPEO_MIN][Square::STAND().index()]=ptype2Val[i]*yVals[5];
00122     for(int y=1;y<10;y++)
00123     {
00124       for(int x=9;x>0;x--)
00125       {
00126         pos2Val[newPtypeO(BLACK,ptype)-PTYPEO_MIN][Square(x,y).index()]
00127           = ptype2Val[i]*yVals[y];
00128         pos2Val[newPtypeO(WHITE,ptype)-PTYPEO_MIN][Square(x,10-y).index()]
00129           = ptype2Val[i]*yVals[y];
00130       }
00131     }
00132   }
00133 }
00134 
00135 osl::progress::PtypeProgressTable::~PtypeProgressTable() {
00136 }
00137 
00138 #ifndef MINIMAL
00139 std::ostream& osl::progress::operator<<(std::ostream& os, PtypeProgress prog)
00140 {
00141   return os << "progress " << prog.progress();
00142 }
00143 #endif
00144 // ;;; Local Variables:
00145 // ;;; mode:c++
00146 // ;;; c-basic-offset:2
00147 // ;;; coding:utf-8
00148 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines