My Project
moveInfo.cc
Go to the documentation of this file.
1 /* moveInfo.cc
2  */
7 #include "osl/eval/see.h"
8 #include "osl/eval/minorPiece.h"
9 using namespace osl::move_classifier;
10 
12 MoveInfo::MoveInfo(const StateInfo& info, Move m)
13  : move(m),
14  see(See::see(*info.state, move, info.pin[info.state->turn()],
15  info.pin[alt(info.state->turn())])),
16  plain_see(see),
17  check(PlayerMoveAdaptor<Check>::isMember(*info.state, move)),
18  open_check(ConditionAdaptor<OpenCheck>::isMember(*info.state, move)),
19  player(m.player()), stand_index_cache(-1)
20 {
21  // ad-hoc adjustment
22  if (adhocAdjustBishopFork(info))
23  see = 0;
24  else if (adhocAdjustSlider(info))
25  see = plain_see / 8;
26  else if (adhocAdjustBreakThreatmate(info))
27  see = 0;
29  see = 0;
30  else if (adhocAdjustKeepCheckmateDefender(info))
31  see = 0;
32 }
33 
35 MoveInfo::adhocAdjustSlider(const StateInfo& info) const
36 {
37  if (plain_see >= 0)
38  return false;
39  const Piece attack = info.state->findCheapAttack(alt(player), move.to());
40  return info.pinByOpposingSliders(attack)
41  && (move.isDrop()
42  || ! info.state->hasEffectByPiece(info.state->pieceAt(move.from()),
43  attack.square()));
44 }
45 
48 {
49  if (plain_see >= 0
50  || !info.state->hasPieceOnStand<BISHOP>(info.state->turn()))
51  return false;
52 
53  const Piece attack
54  = info.state->findCheapAttack(alt(player), move.to());
55  if (unpromote(attack.ptype()) == ROOK) {
56  const Player defense = alt(info.state->turn());
57  const Square king = info.state->kingSquare(defense);
58  const Square center
59  = eval::ml::BishopRookFork::isBishopForkSquare(*info.state, defense, king, move.to(), true);
60  return ! center.isPieceStand();
61  }
62  return false;
63 }
64 
67 {
68  if (! info.threatmate_move.isNormal())
69  return false;
70 
71  const Piece attack
72  = info.state->findCheapAttack(alt(player), move.to());
73  if (attack.isPiece() // break threatmate by sacrifice
74  && info.state->hasEffectByPiece(attack, info.threatmate_move.to()))
75  return ! info.state->hasEffectIf(attack.ptypeO(), move.to(),
76  info.threatmate_move.to());
77  return false;
78 }
79 
82 {
83  if (plain_see >= 0)
84  return false;
85  const Piece defender = info.checkmate_defender[alt(player)].first;
86  if (defender.isPiece()
87  && info.state->countEffect(alt(player), move.to()) == 1
88  && info.state->hasEffectByPiece(defender, move.to()))
89  return true;
90  return false;
91 }
92 
95 {
96  if (plain_see <= 0)
97  return false;
98  const Piece defender = info.checkmate_defender[player].first;
99  const Square threat_at = info.checkmate_defender[player].second;
100  if (defender.isPiece() && move.from() == defender.square()
101  && ! info.state->hasEffectIf(move.ptypeO(), move.to(), threat_at))
102  return true;
103  return false;
104 }
105 
106 // ;;; Local Variables:
107 // ;;; mode:c++
108 // ;;; c-basic-offset:2
109 // ;;; End:
osl::move_probability::MoveInfo::adhocAdjustKeepCheckmateDefender
bool adhocAdjustKeepCheckmateDefender(const StateInfo &) const
Definition: moveInfo.cc:94
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition: simpleState.h:167
osl::Square
Definition: basic_type.h:532
osl::NumEffectState::findCheapAttack
const Piece findCheapAttack(Player P, Square square) const
Definition: numEffectState.h:560
osl::move_probability::StateInfo::threatmate_move
Move threatmate_move
Definition: stateInfo.h:35
osl::move_classifier::Check
Definition: check_.h:16
osl::move_classifier::ConditionAdaptor
drop の時は呼べないなどの条件を代わりにテスト
Definition: moveAdaptor.h:38
osl::move_probability::MoveInfo::adhocAdjustAttackCheckmateDefender
bool adhocAdjustAttackCheckmateDefender(const StateInfo &) const
Definition: moveInfo.cc:81
osl::move_probability::MoveInfo::MoveInfo
MoveInfo(const StateInfo &, Move)
Definition: moveInfo.cc:12
osl::alt
constexpr Player alt(Player player)
Definition: basic_type.h:13
osl::move_classifier
Definition: check_.h:10
osl::move_probability::MoveInfo::adhocAdjustBishopFork
bool adhocAdjustBishopFork(const StateInfo &) const
Definition: moveInfo.cc:47
osl::Move
圧縮していない moveの表現 .
Definition: basic_type.h:1052
osl::Piece::ptypeO
PtypeO ptypeO() const
Definition: basic_type.h:824
osl::move_probability::StateInfo::pinByOpposingSliders
bool pinByOpposingSliders(Piece p) const
Definition: stateInfo.h:83
osl::NumEffectState::hasEffectIf
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
Definition: numEffectState.h:465
osl::move_probability::StateInfo
Definition: stateInfo.h:21
osl::move_classifier::OpenCheck
Definition: openCheck.h:16
osl::Piece
駒.
Definition: basic_type.h:788
see.h
osl::move_probability::MoveInfo::adhocAdjustBreakThreatmate
bool adhocAdjustBreakThreatmate(const StateInfo &) const
Definition: moveInfo.cc:66
osl::move_probability::StateInfo::state
const NumEffectState * state
Definition: stateInfo.h:22
osl::Square::isPieceStand
bool isPieceStand() const
Definition: basic_type.h:576
osl::BISHOP
@ BISHOP
Definition: basic_type.h:99
osl::move_probability::MoveInfo::adhocAdjustSlider
bool adhocAdjustSlider(const StateInfo &) const
Definition: moveInfo.cc:35
osl::NumEffectState::hasEffectByPiece
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
Definition: numEffectState.h:450
minorPiece.h
osl::Move::isNormal
bool isNormal() const
INVALID でも PASS でもない.
Definition: basic_type.h:1088
osl::move_probability::StateInfo::checkmate_defender
CArray< std::pair< Piece, Square >, 2 > checkmate_defender
Definition: stateInfo.h:42
osl::SimpleState::hasPieceOnStand
bool hasPieceOnStand(Player player, Ptype ptype) const
Definition: simpleState.h:191
osl::Piece::isPiece
bool isPiece() const
Definition: basic_type.h:953
osl::ROOK
@ ROOK
Definition: basic_type.h:100
osl::move_probability::MoveInfo::see
int see
Definition: moveInfo.h:16
osl::SimpleState::kingSquare
Square kingSquare() const
Definition: simpleState.h:94
osl::Piece::square
const Square square() const
Definition: basic_type.h:832
osl::Piece::ptype
Ptype ptype() const
Definition: basic_type.h:821
moveAdaptor.h
check_.h
moveInfo.h
stateInfo.h
osl::move_classifier::PlayerMoveAdaptor
Definition: moveAdaptor.h:23
osl::SimpleState::turn
Player turn() const
Definition: simpleState.h:220
osl::Player
Player
Definition: basic_type.h:8
osl::Move::to
const Square to() const
Definition: basic_type.h:1132
osl::move_probability::MoveInfo::plain_see
int plain_see
Definition: moveInfo.h:16
osl::NumEffectState::countEffect
int countEffect(Player player, Square target) const
利きの数を数える.
Definition: numEffectState.h:266
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
osl::eval::See
Definition: see.h:14
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
Definition: basic_type.h:157