pin.h
Go to the documentation of this file.
/* pin.h
*/
#ifndef EVAL_ML_PIN_H
#define EVAL_ML_PIN_H
#include "osl/numEffectState.h"
#include "osl/eval/weights.h"
#include "osl/eval/midgame.h"
#include <cstdlib>
namespace osl
{
namespace eval
{
namespace ml
{
class SimplePin
{
static CArray<int, PTYPE_SIZE> table;
public:
SimplePin() { };
static void setUp(const Weights &weights);
int eval(const NumEffectState &state,
PieceMask black_mask, PieceMask white_mask) const;
};
class Pin
{
static int index(const Square king,
const Piece piece)
{
return std::abs(piece.square().x() - king.x()) * 17 +
(piece.owner() == BLACK ? (king.y() - piece.square().y()) :
(piece.square().y() - king.y())) + 8;
}
static CArray2d<MultiInt, PTYPE_SIZE, 17 * 9> table;
public:
enum { DIM = (osl::PTYPE_MAX - osl::PTYPE_PIECE_MIN + 1) * 17 * 9};
Pin() { };
static void setUp(const Weights &weights,int stage);
static MultiInt eval(const NumEffectState &state,
PieceMask black_mask, PieceMask white_mask);
};
class PinPtypeAll
{
public:
static MultiInt eval(const NumEffectState &state);
private:
template <Player Defense>
static MultiInt evalOne(const NumEffectState &state);
template <Player Defense>
static bool pawnAttack(const NumEffectState &state, Piece piece)
{
const Square up =
piece.square() + DirectionPlayerTraits<U, Defense>::offset();
return (up.isOnBoard() &&
(state.hasEffectByPtypeStrict<PAWN>(alt(Defense), up)
|| (!state.isPawnMaskSet(alt(Defense),
piece.square().x())
&& state.pieceAt(up).isEmpty())));
}
protected:
static CArray<MultiInt, 80> table;
static CArray<MultiInt, 48> pawn_table;
static CArray<MultiInt, 560> distance_table;
};
class PinPtype : public PinPtypeAll
{
public:
enum { ONE_DIM = 80, DIM = ONE_DIM * EvalStages };
static void setUp(const Weights &weights);
};
class PinPtypeDistance : public PinPtypeAll
{
public:
enum { ONE_DIM = 560, DIM = ONE_DIM * EvalStages };
static void setUp(const Weights &weights);
};
class PinPtypePawnAttack : public PinPtypeAll
{
public:
enum { ONE_DIM = 48, DIM = ONE_DIM * EvalStages };
static void setUp(const Weights &weights);
};
class CheckShadowPtype
{
public:
enum {
// rook v, rook h, bishop u, bishop d, lance
ONE_DIM = PTYPE_SIZE * 5,
DIM = ONE_DIM * EvalStages
};
static void setUp(const Weights &weights);
static MultiInt eval(const NumEffectState &state);
template <Player King>
static MultiInt evalOne(const NumEffectState &state);
static CArray<MultiInt, ONE_DIM> table;
};
}
}
}
#endif // EVAL_ML_PIN_H
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::CArray
Definition container.h:20
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::hasEffectByPtypeStrict
bool hasEffectByPtypeStrict(Player attack, Square target) const
target に ptype の利きがあるか?
Definition numEffectState.h:363
osl::PieceMask
駒番号のビットセット.
Definition pieceMask.h:21
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::square
const Square square() const
Definition basic_type.h:832
osl::Piece::isEmpty
bool isEmpty() const
Definition basic_type.h:913
osl::Piece::owner
Player owner() const
Definition basic_type.h:963
osl::SimpleState::isPawnMaskSet
bool isPawnMaskSet(Player player, int x) const
Definition simpleState.h:146
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition simpleState.h:167
osl::Square
Definition basic_type.h:532
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
osl::Square::isOnBoard
bool isOnBoard() const
盤面上を表すかどうかの判定． 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する．
Definition basic_type.h:583
osl::Square::x
int x() const
将棋としてのX座標を返す.
Definition basic_type.h:563
osl::eval::ml::CheckShadowPtype
Definition pin.h:91
osl::eval::ml::CheckShadowPtype::evalOne
static MultiInt evalOne(const NumEffectState &state)
osl::eval::ml::CheckShadowPtype::setUp
static void setUp(const Weights &weights)
Definition eval_pin.cc:196
osl::eval::ml::CheckShadowPtype::table
static CArray< MultiInt, ONE_DIM > table
Definition pin.h:102
osl::eval::ml::CheckShadowPtype::ONE_DIM
@ ONE_DIM
Definition pin.h:95
osl::eval::ml::CheckShadowPtype::DIM
@ DIM
Definition pin.h:96
osl::eval::ml::PinPtypeAll
Definition pin.h:46
osl::eval::ml::PinPtypeAll::pawnAttack
static bool pawnAttack(const NumEffectState &state, Piece piece)
Definition pin.h:53
osl::eval::ml::PinPtypeAll::pawn_table
static CArray< MultiInt, 48 > pawn_table
Definition pin.h:65
osl::eval::ml::PinPtypeAll::distance_table
static CArray< MultiInt, 560 > distance_table
Definition pin.h:66
osl::eval::ml::PinPtypeAll::table
static CArray< MultiInt, 80 > table
Definition pin.h:64
osl::eval::ml::PinPtypeAll::eval
static MultiInt eval(const NumEffectState &state)
Definition eval_pin.cc:186
osl::eval::ml::PinPtypeAll::evalOne
static MultiInt evalOne(const NumEffectState &state)
osl::eval::ml::PinPtypeDistance
Definition pin.h:77
osl::eval::ml::PinPtypeDistance::DIM
@ DIM
Definition pin.h:79
osl::eval::ml::PinPtypeDistance::ONE_DIM
@ ONE_DIM
Definition pin.h:79
osl::eval::ml::PinPtypeDistance::setUp
static void setUp(const Weights &weights)
Definition eval_pin.cc:95
osl::eval::ml::PinPtypePawnAttack
Definition pin.h:84
osl::eval::ml::PinPtypePawnAttack::ONE_DIM
@ ONE_DIM
Definition pin.h:86
osl::eval::ml::PinPtypePawnAttack::DIM
@ DIM
Definition pin.h:86
osl::eval::ml::PinPtypePawnAttack::setUp
static void setUp(const Weights &weights)
Definition eval_pin.cc:105
osl::eval::ml::PinPtype
Definition pin.h:70
osl::eval::ml::PinPtype::setUp
static void setUp(const Weights &weights)
Definition eval_pin.cc:85
osl::eval::ml::PinPtype::ONE_DIM
@ ONE_DIM
Definition pin.h:72
osl::eval::ml::PinPtype::DIM
@ DIM
Definition pin.h:72
osl::eval::ml::Pin::DIM
@ DIM
Definition pin.h:38
osl::eval::ml::Pin::table
static CArray2d< MultiInt, PTYPE_SIZE, 17 *9 > table
Definition pin.h:36
osl::eval::ml::Pin::Pin
Pin()
Definition pin.h:39
osl::eval::ml::Pin::setUp
static void setUp(const Weights &weights, int stage)
Definition eval_pin.cc:41
osl::eval::ml::Pin::index
static int index(const Square king, const Piece piece)
Definition pin.h:29
osl::eval::ml::SimplePin::table
static CArray< int, PTYPE_SIZE > table
Definition pin.h:19
osl::eval::ml::SimplePin::SimplePin
SimplePin()
Definition pin.h:21
osl::eval::ml::SimplePin::setUp
static void setUp(const Weights &weights)
Definition eval_pin.cc:11
midgame.h
osl::eval::ml
Definition eval_pieceStand.cc:470
osl::eval
Definition eval_pieceStand.cc:468
osl
Definition additionalEffect.h:6
osl::PTYPE_PIECE_MIN
@ PTYPE_PIECE_MIN
Definition basic_type.h:104
osl::PTYPE_MAX
@ PTYPE_MAX
Definition basic_type.h:105
osl::PAWN
@ PAWN
Definition basic_type.h:95
osl::CArray2d
CArray< CArray< T, Capacity2 >, Capacity1 > CArray2d
Definition container.h:95
osl::PTYPE_SIZE
const int PTYPE_SIZE
Definition basic_type.h:107
osl::MultiInt
QuadInt MultiInt
Definition midgame.h:13
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
numEffectState.h
osl::DirectionPlayerTraits
Definition directionTraits.h:242
osl::eval::ml::Weights
Definition weights.h:18
weights.h