ptypeEval.cc
Go to the documentation of this file.
#include "osl/eval/ptypeEval.h"
osl::eval::PtypeEvalTable::PtypeEvalTable()
{
init();
}
void osl::eval::PtypeEvalTable::init()
{
const CArray<int, PTYPE_SIZE> values = {
0, 0,
PtypeEvalTraits<PPAWN>::val, PtypeEvalTraits<PLANCE>::val,
PtypeEvalTraits<PKNIGHT>::val, PtypeEvalTraits<PSILVER>::val,
PtypeEvalTraits<PBISHOP>::val, PtypeEvalTraits<PROOK>::val,
//
PtypeEvalTraits<KING>::val, PtypeEvalTraits<GOLD>::val,
//
PtypeEvalTraits<PAWN>::val, PtypeEvalTraits<LANCE>::val,
PtypeEvalTraits<KNIGHT>::val, PtypeEvalTraits<SILVER>::val,
PtypeEvalTraits<BISHOP>::val, PtypeEvalTraits<ROOK>::val,
};
reset(values);
}
osl::eval::PtypeEvalTable::~PtypeEvalTable()
{
}
void osl::eval::PtypeEvalTable::reset(const CArray<int,PTYPE_SIZE>& values)
{
ptypeO2Val.fill(0);
std::copy(values.begin(), values.end(), ptypeO2Val.begin()+16);
for(int i=PTYPE_MIN;i<=PTYPE_MAX;i++)
{
Ptype ptype=static_cast<Ptype>(i);
ptypeO2Val[newPtypeO(WHITE,ptype)-PTYPEO_MIN]=
-ptypeO2Val[newPtypeO(BLACK,ptype)-PTYPEO_MIN];
}
for(int i=PTYPEO_MIN;i<=PTYPEO_MAX;i++)
{
PtypeO ptypeO=static_cast<PtypeO>(i);
PtypeO basicPtypeO=unpromote(ptypeO);
// note: value() depends on ptypeO2Val
promoteVal[i-PTYPEO_MIN]=this->value(ptypeO)-this->value(basicPtypeO);
}
// EMPTYのcapture
captureVal[0]=0;
for(int i=PTYPEO_MIN;i<=PTYPEO_MAX;i++)
{
PtypeO ptypeO=static_cast<PtypeO>(i);
// note: value() depends on ptypeO2Val
if(isPiece(ptypeO))
captureVal[i-PTYPEO_MIN]=this->value(captured(ptypeO))-
this->value(ptypeO);
else
captureVal[i-PTYPEO_MIN]=0;
}
}
/* ------------------------------------------------------------------------- */
osl::CArray<int, osl::PTYPEO_SIZE> osl::eval::ml::PieceEval::table;
void osl::eval::ml::
PieceEval::setUp(const Weights &weights)
{
table.fill(0);
// WHITE 0-15, BLACK 16-31
for (size_t i = 0; i < weights.dimension(); ++i)
{
table[i - (size_t)PTYPEO_MIN] = weights.value(i);
table[i] = -weights.value(i);
}
table[newPtypeO(BLACK,KING)-PTYPEO_MIN] = osl::eval::Ptype_Eval_Table.value(KING);
table[newPtypeO(WHITE,KING)-PTYPEO_MIN] = -osl::eval::Ptype_Eval_Table.value(KING);
}
int osl::eval::ml::
PieceEval::eval(const NumEffectState &state)
{
int value = 0;
for (int i = 0; i < Piece::SIZE; ++i)
{
const Piece piece = state.pieceOf(i);
value += table[piece.ptypeO() - PTYPEO_MIN];
}
return value;
}
int osl::eval::ml::
PieceEval::value(PtypeO ptypeO)
{
return table[ptypeO - PTYPEO_MIN];
}
/* ------------------------------------------------------------------------- */
osl::CArray
Definition container.h:20
osl::CArray::end
iterator end()
Definition container.h:65
osl::CArray::begin
iterator begin()
Definition container.h:64
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptypeO
PtypeO ptypeO() const
Definition basic_type.h:824
osl::Piece::SIZE
static const int SIZE
Definition basic_type.h:794
osl::SimpleState::pieceOf
const Piece pieceOf(int num) const
Definition simpleState.h:76
osl::eval::PtypeEvalTable::ptypeO2Val
CArray< int, PTYPEO_SIZE > ptypeO2Val
Definition ptypeEval.h:18
osl::eval::PtypeEvalTable::captureVal
CArray< int, PTYPEO_SIZE > captureVal
Definition ptypeEval.h:20
osl::eval::PtypeEvalTable::~PtypeEvalTable
~PtypeEvalTable()
Definition ptypeEval.cc:22
osl::eval::PtypeEvalTable::PtypeEvalTable
PtypeEvalTable()
Definition ptypeEval.cc:2
osl::eval::PtypeEvalTable::promoteVal
CArray< int, PTYPEO_SIZE > promoteVal
Definition ptypeEval.h:19
osl::eval::PtypeEvalTable::reset
void reset(const CArray< int, PTYPE_SIZE > &values)
Definition ptypeEval.cc:26
osl::eval::PtypeEvalTable::init
void init()
Definition ptypeEval.cc:6
osl::eval::PtypeEvalTable::value
int value(PtypeO ptypeO) const
先手から見たptypeOの駒の価値
Definition ptypeEval.h:29
osl::eval::ml::PieceEval::setUp
static void setUp(const Weights &weights)
Definition ptypeEval.cc:63
osl::eval::ml::PieceEval::table
static CArray< int, PTYPEO_SIZE > table
Definition ptypeEval.h:84
osl::eval::ml::PieceEval::value
static int value(PtypeO ptypeO)
Definition ptypeEval.cc:89
osl::eval::ml::PieceEval::eval
static int eval(const NumEffectState &state)
Definition ptypeEval.cc:77
osl::eval::Ptype_Eval_Table
const PtypeEvalTable Ptype_Eval_Table
Definition tables.cc:103
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::PTYPE_MAX
@ PTYPE_MAX
Definition basic_type.h:105
osl::KING
@ KING
Definition basic_type.h:93
osl::PTYPE_MIN
@ PTYPE_MIN
Definition basic_type.h:102
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に，promote前の型を返す． promoteしていない型の時はそのまま返す
Definition basic_type.h:157
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::isPiece
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
Definition basic_type.h:120
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
osl::PTYPEO_MAX
@ PTYPEO_MAX
Definition basic_type.h:201
osl::PTYPEO_MIN
@ PTYPEO_MIN
Definition basic_type.h:200
osl::newPtypeO
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
osl::captured
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に，ownerを反転する．
Definition basic_type.h:264
ptypeEval.h
osl::eval::PtypeEvalTraits
Definition ptypeEvalTraits.h:12
osl::eval::ml::Weights
Definition weights.h:18
osl::eval::ml::Weights::dimension
size_t dimension() const
Definition weights.h:29
osl::eval::ml::Weights::value
int value(size_t index) const
Definition weights.h:27