ptypeEval.h
Go to the documentation of this file.
/* pieceEval.h
*/
#ifndef OSL_PTYPEEVAL_H
#define OSL_PTYPEEVAL_H
#include "osl/eval/ptypeEvalTraits.h"
#include "osl/eval/evalTraits.h"
#include "osl/numEffectState.h"
#include <cassert>
namespace osl
{
namespace eval
{
class PtypeEvalTable
{
protected:
CArray<int, PTYPEO_SIZE> ptypeO2Val;
CArray<int, PTYPEO_SIZE> promoteVal;
CArray<int, PTYPEO_SIZE> captureVal;
public:
PtypeEvalTable();
~PtypeEvalTable();
void init();
public:
int value(PtypeO ptypeO) const{
assert(isValidPtypeO(ptypeO));
return ptypeO2Val[ptypeO-PTYPEO_MIN];
}
int value(Ptype ptype) const{
assert(isValid(ptype));
return ptypeO2Val[ptype-PTYPEO_MIN];
}
int promoteValue(PtypeO ptypeO) const{
assert(isPromoted(ptypeO));
return promoteVal[ptypeO-PTYPEO_MIN];
}
int captureValue(PtypeO ptypeO) const{
assert(isValidPtypeO(ptypeO));
return captureVal[ptypeO-PTYPEO_MIN];
}
int diffWithMove(const NumEffectState&, Move move) const {
int ret = 0;
if (move.capturePtype() != PTYPE_EMPTY)
ret += captureValue(move.capturePtypeO());
if (move.isPromotion())
ret+=promoteValue(move.ptypeO());
return ret;
}
void reset(const CArray<int, PTYPE_SIZE>& values);
};
extern const PtypeEvalTable Ptype_Eval_Table;
} // namespace eval
} // namespace osl
#endif /* OSL_PTYPEEVAL_H */
#ifndef EVAL_ML_PIECEEVAL_H
#define EVAL_ML_PIECEEVAL_H
#include "osl/eval/weights.h"
namespace osl
{
namespace eval
{
namespace ml
{
class PieceEval
{
static CArray<int, PTYPEO_SIZE> table;
public:
static void setUp(const Weights &weights);
static int eval(const NumEffectState &state);
template<Player P>
static int evalWithUpdate(const NumEffectState &,
Move moved, int last_value)
{
assert(moved.player()==P);
int value = last_value;
if (moved.isPass() || moved.isDrop())
return last_value;
if (moved.isPromotion())
{
value -= table[moved.oldPtypeO() - PTYPEO_MIN];
value += table[moved.ptypeO() - PTYPEO_MIN];
}
Ptype captured = moved.capturePtype();
if (captured != PTYPE_EMPTY)
{
value -= table[newPtypeO(alt(P), captured) - PTYPEO_MIN];
value += table[newPtypeO(P, unpromote(captured)) - PTYPEO_MIN];
}
return value;
}
static int value(PtypeO ptypeO);
};
}
}
}
#endif // EVAL_ML_PIECEEVAL_H
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::CArray
Definition container.h:20
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::ptypeO
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Definition basic_type.h:1162
osl::Move::isPromotion
bool isPromotion() const
Definition basic_type.h:1147
osl::Move::player
Player player() const
Definition basic_type.h:1195
osl::Move::oldPtypeO
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
Definition basic_type.h:1168
osl::Move::isDrop
bool isDrop() const
Definition basic_type.h:1150
osl::Move::isPass
bool isPass() const
Definition basic_type.h:1092
osl::Move::capturePtype
Ptype capturePtype() const
Definition basic_type.h:1180
osl::Move::capturePtypeO
PtypeO capturePtypeO() const
Definition basic_type.h:1185
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
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::captureValue
int captureValue(PtypeO ptypeO) const
ownerのptypeOがcaptureされた時の評価値の増減
Definition ptypeEval.h:50
osl::eval::PtypeEvalTable::PtypeEvalTable
PtypeEvalTable()
Definition ptypeEval.cc:2
osl::eval::PtypeEvalTable::diffWithMove
int diffWithMove(const NumEffectState &, Move move) const
Definition ptypeEval.h:54
osl::eval::PtypeEvalTable::promoteValue
int promoteValue(PtypeO ptypeO) const
ptypeOにpromoteした時の評価値の増減
Definition ptypeEval.h:43
osl::eval::PtypeEvalTable::value
int value(Ptype ptype) const
ptypeの駒の価値
Definition ptypeEval.h:36
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
Definition ptypeEval.h:83
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::evalWithUpdate
static int evalWithUpdate(const NumEffectState &, Move moved, int last_value)
Definition ptypeEval.h:89
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
evalTraits.h
osl::eval
Definition eval_pieceStand.cc:468
osl::eval::Ptype_Eval_Table
const PtypeEvalTable Ptype_Eval_Table
Definition tables.cc:103
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::PTYPE_EMPTY
@ PTYPE_EMPTY
Definition basic_type.h:85
osl::isValidPtypeO
bool isValidPtypeO(int ptypeO)
Definition basic_type.cc:30
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に，promote前の型を返す． promoteしていない型の時はそのまま返す
Definition basic_type.h:157
osl::isValid
bool isValid(Player player)
cast等で作られたplayerが正しいかどうかを返す
Definition basic_type.cc:9
osl::isPromoted
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Definition basic_type.h:137
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
osl::PTYPEO_MIN
@ PTYPEO_MIN
Definition basic_type.h:200
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
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
numEffectState.h
ptypeEvalTraits.h
osl::eval::ml::Weights
Definition weights.h:18
weights.h