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