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 
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 
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:
bool pinByOpposingSliders(Piece p) const
Definition: stateInfo.h:83
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す ...
Definition: basic_type.h:157
int countEffect(Player player, Square target) const
利きの数を数える.
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる...
drop の時は呼べないなどの条件を代わりにテスト
Definition: moveAdaptor.h:37
bool adhocAdjustBishopFork(const StateInfo &) const
Definition: moveInfo.cc:47
constexpr Player alt(Player player)
Definition: basic_type.h:13
Ptype ptype() const
Definition: basic_type.h:821
bool isPiece() const
Definition: basic_type.h:953
const Piece pieceAt(Square sq) const
Definition: simpleState.h:167
PtypeO ptypeO() const
Definition: basic_type.h:824
bool isNormal() const
INVALID でも PASS でもない.
Definition: basic_type.h:1088
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Definition: basic_type.h:1162
CArray< std::pair< Piece, Square >, 2 > checkmate_defender
Definition: stateInfo.h:42
Square kingSquare() const
Definition: simpleState.h:94
bool adhocAdjustSlider(const StateInfo &) const
Definition: moveInfo.cc:35
const Square from() const
Definition: basic_type.h:1125
圧縮していない moveの表現 .
Definition: basic_type.h:1051
bool hasPieceOnStand(Player player, Ptype ptype) const
Definition: simpleState.h:191
bool adhocAdjustKeepCheckmateDefender(const StateInfo &) const
Definition: moveInfo.cc:94
bool adhocAdjustAttackCheckmateDefender(const StateInfo &) const
Definition: moveInfo.cc:81
Player turn() const
Definition: simpleState.h:220
const Square square() const
Definition: basic_type.h:832
bool isDrop() const
Definition: basic_type.h:1150
const Square to() const
Definition: basic_type.h:1132
const NumEffectState * state
Definition: stateInfo.h:22
const Piece findCheapAttack(Player P, Square square) const
MoveInfo(const StateInfo &, Move)
Definition: moveInfo.cc:12
static const Square isBishopForkSquare(const NumEffectState &state, Player defense, const Square a, const Square b, bool maybe_empty=false)
Definition: minorPiece.cc:2495
Player
Definition: basic_type.h:8
bool adhocAdjustBreakThreatmate(const StateInfo &) const
Definition: moveInfo.cc:66
bool isPieceStand() const
Definition: basic_type.h:576