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