eval/pieceStand.h
Go to the documentation of this file.
/* pieceStand.h
*/
#ifndef EVAL_ML_PIECESTAND_H
#define EVAL_ML_PIECESTAND_H
#include "osl/eval/weights.h"
#include "osl/eval/minorPiece.h"
#include "osl/eval/evalStagePair.h"
#include "osl/numEffectState.h"
#include "osl/bits/king8Info.h"
namespace osl
{
namespace eval
{
namespace ml
{
class PieceStand
{
static CArray<MultiInt, osl::Piece::SIZE> table;
public:
enum { DIM = osl::Piece::SIZE };
PieceStand() { };
static void setUp(const Weights &weights,int stage);
static MultiInt eval(const NumEffectState &state);
template<Player P>
static MultiInt evalWithUpdate(const NumEffectState &state,
Move moved, MultiInt last_value)
{
assert(moved.player()==P);
osl::Ptype captured = moved.capturePtype();
if (moved.isDrop())
{
const int count =
state.countPiecesOnStand(P, moved.ptype()) + 1;
const MultiInt value =
table[Ptype_Table.getIndexMin(moved.ptype()) + count - 1];
if(P==BLACK)
return last_value - value;
else
return last_value + value;
}
else if (captured != PTYPE_EMPTY)
{
Ptype ptype = unpromote(captured);
const int count = state.countPiecesOnStand(P, ptype);
const MultiInt value = table[(Ptype_Table.getIndexMin(ptype) + count - 1)];
if(P==BLACK)
return last_value + value;
else
return last_value - value;
}
else
return last_value;
}
};
class NonPawnPieceStand
{
static CArray<MultiInt, 21> table;
public:
enum { DIM = 21 };
NonPawnPieceStand() { };
static void setUp(const Weights &weights,int stage);
static MultiInt eval(int black_count, int white_count);
};
class NonPawnPieceStandCombination
{
friend class CanCheckNonPawnPieceStandCombination;
public:
enum { ONE_DIM = 5625, DIM = ONE_DIM * EvalStages};
NonPawnPieceStandCombination() { };
static void setUp(const Weights &weights);
static MultiInt eval(const NumEffectState &state,
const CArray<bool, 2> &can_check);
static MultiInt evalWithUpdate(
const NumEffectState &state,
Move moved, const MultiInt &last_value,
const CArray<bool, 2> &could_check,
const CArray<bool, 2> &can_check);
private:
static MultiInt sumUp(const CArray<int, 6> &indices,
const CArray<MultiInt, 5625> &values);
static int index(int rook, int bishop, int gold, int silver,
int knight, int lance)
{
return lance +
5 * (knight + 5 * (silver + 5 * (gold + 5 * (3 * bishop + rook))));
}
static CArray<MultiInt, 5625> table;
static CArray<MultiInt, 5625> check_table;
};
class NonPawnPieceStandTurn
{
public:
enum { ONE_DIM = 44, DIM = ONE_DIM * EvalStages };
NonPawnPieceStandTurn() { };
static void setUp(const Weights &weights);
static void eval(const NumEffectState &state, MultiIntPair& out);
template<Player P>
static void evalWithUpdateBang(
const NumEffectState &state,
Move moved, MultiIntPair &last_value_and_out);
private:
static CArray<MultiInt, 44> table;
static int index(Player player, Player turn, Ptype ptype, int count)
{
return Ptype_Table.getIndexMin(ptype) - 18 + count +
(turn == player ? 22 : 0);
}
};
class PieceStandY
{
private:
static CArray<MultiInt, 360> y_attack_table;
static CArray<MultiInt, 360> y_defense_table;
static CArray<MultiInt, 9*7*19> y_attack_table_sum;
static CArray<MultiInt, 9*7*19> y_defense_table_sum;
static int index(Ptype ptype, Player player, Square king, int count)
{
const int king_y = (player == BLACK ? king.y() : 10 - king.y());
return (king_y - 1) * 40 + Ptype_Table.getIndexMin(ptype) + count;
}
static int index(int i, Player player, Square king, int count)
{
const int king_y = (player == BLACK ? king.y() : 10 - king.y());
return (king_y - 1) * 7*19 + i*19 + count;
}
static void updateResult(NumEffectState const& state, MultiInt &result,int i, Ptype ptype, CArray<Square,2> const&kings);
public:
enum { ONE_DIM = osl::Piece::SIZE * 9, DIM = ONE_DIM * 2*EvalStages };
static void setUp(const Weights &weights);
static MultiInt eval(const NumEffectState &state);
template<Player P>
static MultiInt evalWithUpdate(
const NumEffectState &state, Move moved,
const MultiInt &last_value);
};
class CanCheckNonPawnPieceStandCombination
{
public:
enum { ONE_DIM = 5625, DIM = ONE_DIM * EvalStages};
static void setUp(const Weights &weights);
template <Player Defense>
static bool canCheck(const NumEffectState &state)
{
const Player Attack=alt(Defense);
const King8Info king(state.Iking8Info(Defense));
return (king.dropCandidate() != 0 ||
king.hasMoveCandidate<Attack>(state) ||
KnightCheck::canCheck<Defense>(state));
}
};
class PieceStandCombinationBoth
{
public:
enum { ONE_DIM = 16384, DIM = ONE_DIM * EvalStages };
static void setUp(const Weights &weights);
static MultiInt eval(const NumEffectState &state);
private:
static CArray<MultiInt, 16384> table;
};
}
}
}
#endif // EVAL_ML_PIECESTAND_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::Move::ptype
Ptype ptype() const
Definition basic_type.h:1155
osl::Move::player
Player player() const
Definition basic_type.h:1195
osl::Move::isDrop
bool isDrop() const
Definition basic_type.h:1150
osl::Move::capturePtype
Ptype capturePtype() const
Definition basic_type.h:1180
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::Iking8Info
uint64_t Iking8Info(Player king) const
Definition numEffectState.h:78
osl::Piece::SIZE
static const int SIZE
Definition basic_type.h:794
osl::SimpleState::countPiecesOnStand
int countPiecesOnStand(Player pl, Ptype ptype) const
持駒の枚数を数える
Definition simpleState.h:182
osl::Square
Definition basic_type.h:532
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
osl::checkmate::King8Info
敵玉の8近傍の状態を表す.
Definition king8Info.h:29
osl::checkmate::King8Info::dropCandidate
unsigned int dropCandidate() const
0-7 bit 目を返す
Definition king8Info.h:49
osl::checkmate::King8Info::hasMoveCandidate
bool hasMoveCandidate(NumEffectState const &state) const
Definition king8Info.h:128
osl::eval::ml::CanCheckNonPawnPieceStandCombination
Definition eval/pieceStand.h:144
osl::eval::ml::CanCheckNonPawnPieceStandCombination::setUp
static void setUp(const Weights &weights)
Definition eval_pieceStand.cc:134
osl::eval::ml::CanCheckNonPawnPieceStandCombination::canCheck
static bool canCheck(const NumEffectState &state)
Definition eval/pieceStand.h:149
osl::eval::ml::CanCheckNonPawnPieceStandCombination::ONE_DIM
@ ONE_DIM
Definition eval/pieceStand.h:146
osl::eval::ml::CanCheckNonPawnPieceStandCombination::DIM
@ DIM
Definition eval/pieceStand.h:146
osl::eval::ml::KnightCheck::canCheck
static bool canCheck(const NumEffectState &state)
Definition minorPiece.h:784
osl::eval::ml::NonPawnPieceStandCombination::setUp
static void setUp(const Weights &weights)
Definition eval_pieceStand.cc:95
osl::eval::ml::NonPawnPieceStandCombination::sumUp
static MultiInt sumUp(const CArray< int, 6 > &indices, const CArray< MultiInt, 5625 > &values)
Definition eval_pieceStand.cc:63
osl::eval::ml::NonPawnPieceStandCombination::check_table
static CArray< MultiInt, 5625 > check_table
Definition eval/pieceStand.h:93
osl::eval::ml::NonPawnPieceStandCombination::table
static CArray< MultiInt, 5625 > table
Definition eval/pieceStand.h:92
osl::eval::ml::NonPawnPieceStandCombination::evalWithUpdate
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, const MultiInt &last_value, const CArray< bool, 2 > &could_check, const CArray< bool, 2 > &can_check)
Definition eval_pieceStand.cc:204
osl::eval::ml::NonPawnPieceStandCombination::CanCheckNonPawnPieceStandCombination
friend class CanCheckNonPawnPieceStandCombination
Definition eval/pieceStand.h:71
osl::eval::ml::NonPawnPieceStandCombination::index
static int index(int rook, int bishop, int gold, int silver, int knight, int lance)
Definition eval/pieceStand.h:86
osl::eval::ml::NonPawnPieceStandCombination::ONE_DIM
@ ONE_DIM
Definition eval/pieceStand.h:73
osl::eval::ml::NonPawnPieceStandCombination::DIM
@ DIM
Definition eval/pieceStand.h:73
osl::eval::ml::NonPawnPieceStandCombination::NonPawnPieceStandCombination
NonPawnPieceStandCombination()
Definition eval/pieceStand.h:74
osl::eval::ml::NonPawnPieceStandTurn::index
static int index(Player player, Player turn, Ptype ptype, int count)
Definition eval/pieceStand.h:109
osl::eval::ml::NonPawnPieceStandTurn::ONE_DIM
@ ONE_DIM
Definition eval/pieceStand.h:99
osl::eval::ml::NonPawnPieceStandTurn::DIM
@ DIM
Definition eval/pieceStand.h:99
osl::eval::ml::NonPawnPieceStandTurn::setUp
static void setUp(const Weights &weights)
Definition eval_pieceStand.cc:223
osl::eval::ml::NonPawnPieceStandTurn::table
static CArray< MultiInt, 44 > table
Definition eval/pieceStand.h:108
osl::eval::ml::NonPawnPieceStandTurn::evalWithUpdateBang
static void evalWithUpdateBang(const NumEffectState &state, Move moved, MultiIntPair &last_value_and_out)
Definition eval_pieceStand.cc:261
osl::eval::ml::NonPawnPieceStandTurn::NonPawnPieceStandTurn
NonPawnPieceStandTurn()
Definition eval/pieceStand.h:100
osl::eval::ml::NonPawnPieceStand::setUp
static void setUp(const Weights &weights, int stage)
Definition eval_pieceStand.cc:44
osl::eval::ml::NonPawnPieceStand::DIM
@ DIM
Definition eval/pieceStand.h:63
osl::eval::ml::NonPawnPieceStand::table
static CArray< MultiInt, 21 > table
Definition eval/pieceStand.h:61
osl::eval::ml::NonPawnPieceStand::NonPawnPieceStand
NonPawnPieceStand()
Definition eval/pieceStand.h:64
osl::eval::ml::PieceStandCombinationBoth
Definition eval/pieceStand.h:159
osl::eval::ml::PieceStandCombinationBoth::DIM
@ DIM
Definition eval/pieceStand.h:161
osl::eval::ml::PieceStandCombinationBoth::ONE_DIM
@ ONE_DIM
Definition eval/pieceStand.h:161
osl::eval::ml::PieceStandCombinationBoth::setUp
static void setUp(const Weights &weights)
Definition eval_pieceStand.cc:423
osl::eval::ml::PieceStandCombinationBoth::table
static CArray< MultiInt, 16384 > table
Definition eval/pieceStand.h:165
osl::eval::ml::PieceStandY
Definition eval/pieceStand.h:116
osl::eval::ml::PieceStandY::y_attack_table
static CArray< MultiInt, 360 > y_attack_table
Definition eval/pieceStand.h:118
osl::eval::ml::PieceStandY::DIM
@ DIM
Definition eval/pieceStand.h:134
osl::eval::ml::PieceStandY::ONE_DIM
@ ONE_DIM
Definition eval/pieceStand.h:134
osl::eval::ml::PieceStandY::index
static int index(Ptype ptype, Player player, Square king, int count)
Definition eval/pieceStand.h:122
osl::eval::ml::PieceStandY::y_attack_table_sum
static CArray< MultiInt, 9 *7 *19 > y_attack_table_sum
Definition eval/pieceStand.h:120
osl::eval::ml::PieceStandY::index
static int index(int i, Player player, Square king, int count)
Definition eval/pieceStand.h:127
osl::eval::ml::PieceStandY::updateResult
static void updateResult(NumEffectState const &state, MultiInt &result, int i, Ptype ptype, CArray< Square, 2 > const &kings)
Definition eval_pieceStand.cc:346
osl::eval::ml::PieceStandY::evalWithUpdate
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, const MultiInt &last_value)
osl::eval::ml::PieceStandY::y_defense_table_sum
static CArray< MultiInt, 9 *7 *19 > y_defense_table_sum
Definition eval/pieceStand.h:121
osl::eval::ml::PieceStandY::y_defense_table
static CArray< MultiInt, 360 > y_defense_table
Definition eval/pieceStand.h:119
osl::eval::ml::PieceStandY::setUp
static void setUp(const Weights &weights)
Definition eval_pieceStand.cc:312
osl::eval::ml::PieceStand::DIM
@ DIM
Definition eval/pieceStand.h:23
osl::eval::ml::PieceStand::evalWithUpdate
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, MultiInt last_value)
Definition eval/pieceStand.h:28
osl::eval::ml::PieceStand::table
static CArray< MultiInt, osl::Piece::SIZE > table
Definition eval/pieceStand.h:21
osl::eval::ml::PieceStand::setUp
static void setUp(const Weights &weights, int stage)
Definition eval_pieceStand.cc:8
osl::eval::ml::PieceStand::PieceStand
PieceStand()
Definition eval/pieceStand.h:24
evalStagePair.h
king8Info.h
minorPiece.h
osl::eval::ml
Definition eval_pieceStand.cc:470
osl::eval
Definition eval_pieceStand.cc:468
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::Ptype_Table
const PtypeTable Ptype_Table
Definition tables.cc:97
osl::MultiIntPair
QuadIntPair MultiIntPair
Definition midgame.h:14
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に，promote前の型を返す． promoteしていない型の時はそのまま返す
Definition basic_type.h:157
osl::MultiInt
QuadInt MultiInt
Definition midgame.h:13
osl::Player
Player
Definition basic_type.h:8
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::EvalStages
const int EvalStages
Definition midgame.h:12
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
osl::captured
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に，ownerを反転する．
Definition basic_type.h:264
numEffectState.h
osl::eval::ml::Weights
Definition weights.h:18
weights.h