moveInfo.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
moveInfo.cc
Go to the documentation of this file.
1 /* moveInfo.cc
2 */
3 #include "osl/move_probability/moveInfo.h"
4 #include "osl/move_probability/stateInfo.h"
5 #include "osl/move_classifier/moveAdaptor.h"
6 #include "osl/move_classifier/check_.h"
7 #include "osl/eval/see.h"
8 #include "osl/eval/ml/minorPiece.h" // todo
9 using namespace osl::move_classifier;
10
11 osl::move_probability::
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;
28 else if (adhocAdjustAttackCheckmateDefender(info))
29 see = 0;
30 else if (adhocAdjustKeepCheckmateDefender(info))
31 see = 0;
32 }
33
34 bool osl::move_probability::
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
46 bool osl::move_probability::
47 MoveInfo::adhocAdjustBishopFork(const StateInfo& info) const
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
65 bool osl::move_probability::
66 MoveInfo::adhocAdjustBreakThreatmate(const StateInfo& info) const
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
80 bool osl::move_probability::
81 MoveInfo::adhocAdjustAttackCheckmateDefender(const StateInfo& info) const
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
93 bool osl::move_probability::
94 MoveInfo::adhocAdjustKeepCheckmateDefender(const StateInfo& info) const
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: