moveInfo.cc
Go to the documentation of this file.
/* moveInfo.cc
*/
#include "osl/move_probability/moveInfo.h"
#include "osl/move_probability/stateInfo.h"
#include "osl/move_classifier/moveAdaptor.h"
#include "osl/move_classifier/check_.h"
#include "osl/eval/see.h"
#include "osl/eval/minorPiece.h"
using namespace osl::move_classifier;
osl::move_probability::
MoveInfo::MoveInfo(const StateInfo& info, Move m)
: move(m),
see(See::see(*info.state, move, info.pin[info.state->turn()],
info.pin[alt(info.state->turn())])),
plain_see(see),
check(PlayerMoveAdaptor<Check>::isMember(*info.state, move)),
open_check(ConditionAdaptor<OpenCheck>::isMember(*info.state, move)),
player(m.player()), stand_index_cache(-1)
{
// ad-hoc adjustment
if (adhocAdjustBishopFork(info))
see = 0;
else if (adhocAdjustSlider(info))
see = plain_see / 8;
else if (adhocAdjustBreakThreatmate(info))
see = 0;
else if (adhocAdjustAttackCheckmateDefender(info))
see = 0;
else if (adhocAdjustKeepCheckmateDefender(info))
see = 0;
}
bool osl::move_probability::
MoveInfo::adhocAdjustSlider(const StateInfo& info) const
{
if (plain_see >= 0)
return false;
const Piece attack = info.state->findCheapAttack(alt(player), move.to());
return info.pinByOpposingSliders(attack)
&& (move.isDrop()
|| ! info.state->hasEffectByPiece(info.state->pieceAt(move.from()),
attack.square()));
}
bool osl::move_probability::
MoveInfo::adhocAdjustBishopFork(const StateInfo& info) const
{
if (plain_see >= 0
|| !info.state->hasPieceOnStand<BISHOP>(info.state->turn()))
return false;
const Piece attack
= info.state->findCheapAttack(alt(player), move.to());
if (unpromote(attack.ptype()) == ROOK) {
const Player defense = alt(info.state->turn());
const Square king = info.state->kingSquare(defense);
const Square center
= eval::ml::BishopRookFork::isBishopForkSquare(*info.state, defense, king, move.to(), true);
return ! center.isPieceStand();
}
return false;
}
bool osl::move_probability::
MoveInfo::adhocAdjustBreakThreatmate(const StateInfo& info) const
{
if (! info.threatmate_move.isNormal())
return false;
const Piece attack
= info.state->findCheapAttack(alt(player), move.to());
if (attack.isPiece() // break threatmate by sacrifice
&& info.state->hasEffectByPiece(attack, info.threatmate_move.to()))
return ! info.state->hasEffectIf(attack.ptypeO(), move.to(),
info.threatmate_move.to());
return false;
}
bool osl::move_probability::
MoveInfo::adhocAdjustAttackCheckmateDefender(const StateInfo& info) const
{
if (plain_see >= 0)
return false;
const Piece defender = info.checkmate_defender[alt(player)].first;
if (defender.isPiece()
&& info.state->countEffect(alt(player), move.to()) == 1
&& info.state->hasEffectByPiece(defender, move.to()))
return true;
return false;
}
bool osl::move_probability::
MoveInfo::adhocAdjustKeepCheckmateDefender(const StateInfo& info) const
{
if (plain_see <= 0)
return false;
const Piece defender = info.checkmate_defender[player].first;
const Square threat_at = info.checkmate_defender[player].second;
if (defender.isPiece() && move.from() == defender.square()
&& ! info.state->hasEffectIf(move.ptypeO(), move.to(), threat_at))
return true;
return false;
}
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
check_.h
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::isNormal
bool isNormal() const
INVALID でも PASS でもない.
Definition basic_type.h:1088
osl::Move::to
const Square to() const
Definition basic_type.h:1132
osl::NumEffectState::countEffect
int countEffect(Player player, Square target) const
利きの数を数える.
Definition numEffectState.h:266
osl::NumEffectState::hasEffectByPiece
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
Definition numEffectState.h:450
osl::NumEffectState::findCheapAttack
const Piece findCheapAttack(Player P, Square square) const
Definition numEffectState.h:560
osl::NumEffectState::hasEffectIf
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
Definition numEffectState.h:465
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptypeO
PtypeO ptypeO() const
Definition basic_type.h:824
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
osl::Piece::square
const Square square() const
Definition basic_type.h:832
osl::Piece::isPiece
bool isPiece() const
Definition basic_type.h:953
osl::SimpleState::hasPieceOnStand
bool hasPieceOnStand(Player player, Ptype ptype) const
Definition simpleState.h:191
osl::SimpleState::turn
Player turn() const
Definition simpleState.h:220
osl::SimpleState::kingSquare
Square kingSquare() const
Definition simpleState.h:94
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition simpleState.h:167
osl::Square
Definition basic_type.h:532
osl::Square::isPieceStand
bool isPieceStand() const
Definition basic_type.h:576
osl::eval::ml::BishopRookFork::isBishopForkSquare
static const Square isBishopForkSquare(const NumEffectState &state, Player defense, const Square a, const Square b, bool maybe_empty=false)
Definition minorPiece.cc:2495
minorPiece.h
moveAdaptor.h
moveInfo.h
osl::move_classifier
Definition check_.h:10
osl::ROOK
@ ROOK
Definition basic_type.h:100
osl::BISHOP
@ BISHOP
Definition basic_type.h:99
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に，promote前の型を返す． promoteしていない型の時はそのまま返す
Definition basic_type.h:157
osl::Player
Player
Definition basic_type.h:8
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
see.h
stateInfo.h
osl::eval::See
Definition see.h:14
osl::move_classifier::Check
Definition check_.h:16
osl::move_classifier::ConditionAdaptor
drop の時は呼べないなどの条件を代わりにテスト
Definition moveAdaptor.h:38
osl::move_classifier::OpenCheck
Definition openCheck.h:16
osl::move_classifier::PlayerMoveAdaptor
Definition moveAdaptor.h:23
osl::move_probability::MoveInfo::stand_index_cache
int stand_index_cache
Definition moveInfo.h:19
osl::move_probability::MoveInfo::see
int see
Definition moveInfo.h:16
osl::move_probability::MoveInfo::player
Player player
Definition moveInfo.h:18
osl::move_probability::MoveInfo::check
bool check
Definition moveInfo.h:17
osl::move_probability::MoveInfo::MoveInfo
MoveInfo(const StateInfo &, Move)
Definition moveInfo.cc:12
osl::move_probability::MoveInfo::adhocAdjustBreakThreatmate
bool adhocAdjustBreakThreatmate(const StateInfo &) const
Definition moveInfo.cc:66
osl::move_probability::MoveInfo::adhocAdjustSlider
bool adhocAdjustSlider(const StateInfo &) const
Definition moveInfo.cc:35
osl::move_probability::MoveInfo::adhocAdjustAttackCheckmateDefender
bool adhocAdjustAttackCheckmateDefender(const StateInfo &) const
Definition moveInfo.cc:81
osl::move_probability::MoveInfo::plain_see
int plain_see
Definition moveInfo.h:16
osl::move_probability::MoveInfo::adhocAdjustKeepCheckmateDefender
bool adhocAdjustKeepCheckmateDefender(const StateInfo &) const
Definition moveInfo.cc:94
osl::move_probability::MoveInfo::move
Move move
Definition moveInfo.h:15
osl::move_probability::MoveInfo::adhocAdjustBishopFork
bool adhocAdjustBishopFork(const StateInfo &) const
Definition moveInfo.cc:47
osl::move_probability::MoveInfo::open_check
bool open_check
Definition moveInfo.h:17
osl::move_probability::StateInfo
Definition stateInfo.h:21
osl::move_probability::StateInfo::state
const NumEffectState * state
Definition stateInfo.h:22
osl::move_probability::StateInfo::threatmate_move
Move threatmate_move
Definition stateInfo.h:35
osl::move_probability::StateInfo::pinByOpposingSliders
bool pinByOpposingSliders(Piece p) const
Definition stateInfo.h:83
osl::move_probability::StateInfo::checkmate_defender
CArray< std::pair< Piece, Square >, 2 > checkmate_defender
Definition stateInfo.h:42