1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#include "osl/progress/ptypeProgress.h"
#include "osl/pieceTable.h"
#include <iostream>
namespace osl
{
namespace progress
{
/** ゲームの進行度を測る駒の種類別の係数 */
template<Ptype T>
struct PtypeProgressTraits;
// 歩
template<>
struct PtypeProgressTraits<PAWN>{
static const int val=2;
};
template<>
struct PtypeProgressTraits<PPAWN>{
static const int val=2;
};
//
template<>
struct PtypeProgressTraits<LANCE>{
static const int val=5;
};
template<>
struct PtypeProgressTraits<PLANCE>{
static const int val=5;
};
//
template<>
struct PtypeProgressTraits<KNIGHT>{
static const int val=5;
};
template<>
struct PtypeProgressTraits<PKNIGHT>{
static const int val=5;
};
//
template<>
struct PtypeProgressTraits<SILVER>{
static const int val=7;
};
template<>
struct PtypeProgressTraits<PSILVER>{
static const int val=7;
};
//
template<>
struct PtypeProgressTraits<GOLD>{
static const int val=8;
};
//
template<>
struct PtypeProgressTraits<BISHOP>{
static const int val=7;
};
template<>
struct PtypeProgressTraits<PBISHOP>{
static const int val=7;
};
//
template<>
struct PtypeProgressTraits<ROOK>{
static const int val=10;
};
template<>
struct PtypeProgressTraits<PROOK>{
static const int val=10;
};
//
template<>
struct PtypeProgressTraits<KING>{
static const int val=15;
};
} // namespace progress
} // namespace osl
osl::progress::
PtypeProgress::PtypeProgress(SimpleState const& state)
{
int ret=0;
for (int num=0; num<Piece::SIZE; num++)
{
if(state.standMask(BLACK).test(num)){
ret+=Ptype_Progress_Table.progress(newPtypeO(BLACK,Piece_Table.getPtypeOf(num)),
Square::STAND());
}
else if(state.standMask(WHITE).test(num)){
ret+=Ptype_Progress_Table.progress(newPtypeO(WHITE,Piece_Table.getPtypeOf(num)),
Square::STAND());
}
else{
assert(state.isOnBoard(num));
const Piece p=state.pieceOf(num);
ret+=Ptype_Progress_Table.progress(p.ptypeO(),p.square());
}
}
val=ret;
}
osl::progress::PtypeProgressTable::PtypeProgressTable()
{
ptype2Val[PAWN]=PtypeProgressTraits<PAWN>::val;
ptype2Val[PPAWN]=PtypeProgressTraits<PPAWN>::val;
ptype2Val[LANCE]=PtypeProgressTraits<LANCE>::val;
ptype2Val[PLANCE]=PtypeProgressTraits<PLANCE>::val;
ptype2Val[KNIGHT]=PtypeProgressTraits<KNIGHT>::val;
ptype2Val[PKNIGHT]=PtypeProgressTraits<PKNIGHT>::val;
ptype2Val[SILVER]=PtypeProgressTraits<SILVER>::val;
ptype2Val[PSILVER]=PtypeProgressTraits<PSILVER>::val;
ptype2Val[GOLD]=PtypeProgressTraits<GOLD>::val;
ptype2Val[KING]=PtypeProgressTraits<KING>::val;
ptype2Val[BISHOP]=PtypeProgressTraits<BISHOP>::val;
ptype2Val[PBISHOP]=PtypeProgressTraits<PBISHOP>::val;
ptype2Val[ROOK]=PtypeProgressTraits<ROOK>::val;
ptype2Val[PROOK]=PtypeProgressTraits<PROOK>::val;
for(int i=PTYPE_MIN;i<=PTYPE_MAX;i++){
Ptype ptype=static_cast<Ptype>(i);
pos2Val[newPtypeO(BLACK,ptype)-PTYPEO_MIN][Square::STAND().index()]=ptype2Val[i]*yVals[5];
pos2Val[newPtypeO(WHITE,ptype)-PTYPEO_MIN][Square::STAND().index()]=ptype2Val[i]*yVals[5];
for(int y=1;y<10;y++)
{
for(int x=9;x>0;x--)
{
pos2Val[newPtypeO(BLACK,ptype)-PTYPEO_MIN][Square(x,y).index()]
= ptype2Val[i]*yVals[y];
pos2Val[newPtypeO(WHITE,ptype)-PTYPEO_MIN][Square(x,10-y).index()]
= ptype2Val[i]*yVals[y];
}
}
}
}
osl::progress::PtypeProgressTable::~PtypeProgressTable() {
}
#ifndef MINIMAL
std::ostream& osl::progress::operator<<(std::ostream& os, PtypeProgress prog)
{
return os << "progress " << prog.progress();
}
#endif
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; coding:utf-8
// ;;; End:
|