piecePair.h
Go to the documentation of this file.
/* piecePair.h
*/
#ifndef OSL_EVAL_PIECEPAIR_H
#define OSL_EVAL_PIECEPAIR_H
#include "osl/eval/weights.h"
#include "osl/eval/evalTraits.h"
#include "osl/numEffectState.h"
#include <iostream>
namespace osl
{
namespace eval
{
namespace ml
{
class PiecePair
{
public:
enum {
plain_table_size = 1338,
x_table_size = 4901,
y_table_size = 7057,
DIM = plain_table_size + x_table_size + y_table_size, // 14 * 12 * PTYPEO_SIZE * PTYPEO_SIZE
};
static int eval(const NumEffectState&, const Weights&);
template<int Direction, int Offset>
static int sum12One(const Piece *basePtr,const int *xbase, const int *ybase);
static int sum12(NumEffectState const& state,Square base,PtypeO ptypeO);
template<int Direction, int Offset>
static int adjust12One(const Piece *basePtr,const int *xbase1, const int *ybase1,const int *xbase2, const int *ybase2);
static int adjust12(NumEffectState const& state,Square base,PtypeO pos,PtypeO neg);
static int evalWithUpdate(const NumEffectState& state, Move moved, int last_value, const Weights& values);
static int evalWithUpdateCompiled(const NumEffectState& state, Move moved, int last_value);
static int pieceValue(const NumEffectState& state, Piece p, const Weights& values);
static int pieceValueDouble(const NumEffectState& state, Piece p, const Weights&);
static int weight(Player attack, int index, const Weights& values)
{
return osl::eval::delta(attack) * values.value(index);
}
typedef CArray<int,3> index_t;
static index_t index(int offset_id, Piece p, Piece q);
static index_t index(int offset_id, Square p0, PtypeO o0, Square p1, PtypeO o1);
static int value(int offset_id, Piece p, Piece q, const Weights& values)
{
assert(p.isOnBoard() && q.isOnBoard());
return value(offset_id, p.square(), p.ptypeO(), q.square(), q.ptypeO(), values);
}
static int value(int offset_id, Piece p, Square p1, PtypeO o1, const Weights& values)
{
return value(offset_id, p.square(), p.ptypeO(), p1, o1, values);
}
static int value(int offset_id, Square p0, PtypeO o0, Square p1, PtypeO o1, const Weights& values)
{
assert(p0 != p1);
index_t idx = index(offset_id, p0, o0, p1, o1);
assert(idx[0] != 0); // do not forget to call init()
int ret = 0;
for (int i=0; i<3; ++i)
ret += (idx[i] > 0) ? values.value(idx[i]) : -values.value(-idx[i]);
return ret;
}
static void init();
static void sanitize(Weights& values);
static void compile(const Weights& values);
static int valueCompiled(int offset_id, Piece p, Square p1, PtypeO o1)
{
return valueCompiled(offset_id, p.square(), p.ptypeO(), p1, o1);
}
static int valueCompiled(int offset_id, Square p0, PtypeO o0, Square p1, PtypeO o1);
// 内部用
struct IndexTable : public CArray3d<signed short, 12, PTYPEO_SIZE, PTYPEO_SIZE>
{
IndexTable();
void fillBW(int index, int dir, Ptype p0, Ptype p1);
void fillSame(int index, int dir, Ptype p0, Ptype p1);
void fillDiffer(int index, int dir, Ptype p0, Ptype p1);
static int pindex(Player player, Ptype ptype)
{
return ptypeOIndex(newPtypeO(player, ptype));
}
void amplify(int base);
};
static IndexTable plain_table;
static CArray<IndexTable, 10> x_table, y_table;
static const CArray<Offset, 12> offsets; // offset_id -> Offset
};
}
}
}
#endif /* OSL_EVAL_ATTACKKING_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::CArray
Definition container.h:20
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
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::square
const Square square() const
Definition basic_type.h:832
osl::Piece::isOnBoard
bool isOnBoard() const
Definition basic_type.h:985
osl::Square
Definition basic_type.h:532
osl::eval::ml::PiecePair
Definition piecePair.h:18
osl::eval::ml::PiecePair::value
static int value(int offset_id, Square p0, PtypeO o0, Square p1, PtypeO o1, const Weights &values)
Definition piecePair.h:57
osl::eval::ml::PiecePair::valueCompiled
static int valueCompiled(int offset_id, Piece p, Square p1, PtypeO o1)
Definition piecePair.h:72
osl::eval::ml::PiecePair::evalWithUpdate
static int evalWithUpdate(const NumEffectState &state, Move moved, int last_value, const Weights &values)
Definition piecePair.cc:461
osl::eval::ml::PiecePair::plain_table
static IndexTable plain_table
Definition piecePair.h:93
osl::eval::ml::PiecePair::evalWithUpdateCompiled
static int evalWithUpdateCompiled(const NumEffectState &state, Move moved, int last_value)
Definition piecePair.cc:595
osl::eval::ml::PiecePair::weight
static int weight(Player attack, int index, const Weights &values)
Definition piecePair.h:40
osl::eval::ml::PiecePair::init
static void init()
Definition piecePair.cc:352
osl::eval::ml::PiecePair::index
static index_t index(int offset_id, Piece p, Piece q)
Definition piecePair.cc:440
osl::eval::ml::PiecePair::value
static int value(int offset_id, Piece p, Piece q, const Weights &values)
Definition piecePair.h:48
osl::eval::ml::PiecePair::sum12One
static int sum12One(const Piece *basePtr, const int *xbase, const int *ybase)
Definition piecePair.cc:529
osl::eval::ml::PiecePair::offsets
static const CArray< Offset, 12 > offsets
Definition piecePair.h:8
osl::eval::ml::PiecePair::sum12
static int sum12(NumEffectState const &state, Square base, PtypeO ptypeO)
Definition piecePair.cc:538
osl::eval::ml::PiecePair::pieceValue
static int pieceValue(const NumEffectState &state, Piece p, const Weights &values)
Definition piecePair.cc:669
osl::eval::ml::PiecePair::adjust12One
static int adjust12One(const Piece *basePtr, const int *xbase1, const int *ybase1, const int *xbase2, const int *ybase2)
Definition piecePair.cc:560
osl::eval::ml::PiecePair::index_t
CArray< int, 3 > index_t
Definition piecePair.h:44
osl::eval::ml::PiecePair::adjust12
static int adjust12(NumEffectState const &state, Square base, PtypeO pos, PtypeO neg)
Definition piecePair.cc:572
osl::eval::ml::PiecePair::compile
static void compile(const Weights &values)
values を展開してクラス全体で使う
Definition piecePair.cc:365
osl::eval::ml::PiecePair::y_table
static CArray< IndexTable, 10 > y_table
Definition piecePair.h:94
osl::eval::ml::PiecePair::sanitize
static void sanitize(Weights &values)
Definition piecePair.cc:396
osl::eval::ml::PiecePair::pieceValueDouble
static int pieceValueDouble(const NumEffectState &state, Piece p, const Weights &)
Definition piecePair.cc:650
osl::eval::ml::PiecePair::value
static int value(int offset_id, Piece p, Square p1, PtypeO o1, const Weights &values)
Definition piecePair.h:53
osl::eval::ml::PiecePair::x_table_size
@ x_table_size
Definition piecePair.h:22
osl::eval::ml::PiecePair::DIM
@ DIM
Definition piecePair.h:24
osl::eval::ml::PiecePair::plain_table_size
@ plain_table_size
Definition piecePair.h:21
osl::eval::ml::PiecePair::y_table_size
@ y_table_size
Definition piecePair.h:23
osl::eval::ml::PiecePair::x_table
static CArray< IndexTable, 10 > x_table
Definition piecePair.h:94
osl::eval::ml::PiecePair::eval
static int eval(const NumEffectState &, const Weights &)
Definition piecePair.cc:450
evalTraits.h
osl::eval::ml
Definition eval_pieceStand.cc:470
osl::eval
Definition eval_pieceStand.cc:468
osl::eval::delta
int delta(Player p)
playerにとってちょっと高い値
Definition evalTraits.h:104
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::CArray3d
CArray< CArray2d< T, Capacity2, Capacity3 >, Capacity1 > CArray3d
Definition container.h:98
osl::ptypeOIndex
unsigned int ptypeOIndex(PtypeO ptypeo)
Definition basic_type.h:205
osl::Player
Player
Definition basic_type.h:8
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
osl::newPtypeO
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
numEffectState.h
osl::eval::ml::PiecePair::IndexTable
Definition piecePair.h:80
osl::eval::ml::PiecePair::IndexTable::pindex
static int pindex(Player player, Ptype ptype)
Definition piecePair.h:87
osl::eval::ml::PiecePair::IndexTable::fillSame
void fillSame(int index, int dir, Ptype p0, Ptype p1)
for same owner
Definition piecePair.cc:332
osl::eval::ml::PiecePair::IndexTable::fillBW
void fillBW(int index, int dir, Ptype p0, Ptype p1)
Definition piecePair.cc:323
osl::eval::ml::PiecePair::IndexTable::fillDiffer
void fillDiffer(int index, int dir, Ptype p0, Ptype p1)
for different owner
Definition piecePair.cc:338
osl::eval::ml::PiecePair::IndexTable::amplify
void amplify(int base)
Definition piecePair.cc:305
osl::eval::ml::PiecePair::IndexTable::IndexTable
IndexTable()
Definition piecePair.cc:299
osl::eval::ml::Weights
Definition weights.h:18
osl::eval::ml::Weights::value
int value(size_t index) const
Definition weights.h:27
weights.h