dualThreatmateState.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
dualThreatmateState.h
Go to the documentation of this file.
1 /* dualThreatmateState.h
2 */
3 #ifndef OSL_SEARCH__DUALTHREATMATESTATE_H
4 #define OSL_SEARCH__DUALTHREATMATESTATE_H
5
6 #include "osl/search/threatmateState.h"
7 #include "osl/effect_util/sendOffSquare.h"
8 #include <iosfwd>
9
10 namespace osl
11 {
12 namespace search
13 {
14 class DualThreatmateState
15 {
16 CArray<Move,2> threatmate_move;
17 CArray<ThreatmateState,2> king_status;
18 ThreatmateState& wstatus(Player king)
19 {
20 return king_status[king];
21 }
22 public:
24 mutable SendOffSquare::SendOff8 sendoffs;
25 #ifdef OSL_SMP
26 volatile
27 #endif
28 struct Flags {
29 bool is_king_in_check:4;
30 char static_value_type:4;
31 } flags;
32 explicit DualThreatmateState(ThreatmateState::Status b=ThreatmateState::UNKNOWN,
33 ThreatmateState::Status w=ThreatmateState::UNKNOWN)
34 : sendoffs(SendOffSquare::invalidData())
35 {
36 wstatus(BLACK) = b;
37 wstatus(WHITE) = w;
38 flags.is_king_in_check = false;
39 flags.static_value_type = 0;
40 }
41 const ThreatmateState& status(Player king) const
42 {
43 return king_status[king];
44 }
45 void setThreatmate(Player king, Move m) {
46 assert(m.isNormal());
47 wstatus(king).setThreatmate(ThreatmateState::THREATMATE);
48 threatmate_move[king] = m;
49 }
50
51 bool isThreatmate(Player king) const {
52 return status(king).isThreatmate();
53 }
54 const Move threatmateMove(Player king) const {
55 return threatmate_move[king];
56 }
57 bool maybeThreatmate(Player king) const {
58 return status(king).maybeThreatmate();
59 }
60 bool mayHaveCheckmate(Player king) const {
61 return status(king).mayHaveCheckmate();
62 }
63 void updateInLock(Player turn, const DualThreatmateState *parent, bool in_check)
64 {
65 if (parent)
66 {
67 if (! maybeThreatmate(turn))
68 wstatus(turn).update(&parent->status(turn), in_check);
69 if (! mayHaveCheckmate(alt(turn)))
70 wstatus(alt(turn)).update(&parent->status(alt(turn)), in_check);
71 }
72 }
73 };
74 std::ostream& operator<<(std::ostream&, DualThreatmateState);
75 }
76 } // namespace osl
77
78 #endif /* OSL_SEARCH__DUALTHREATMATESTATE_H */
79 // ;;; Local Variables:
80 // ;;; mode:c++
81 // ;;; c-basic-offset:2
82 // ;;; coding:utf-8
83 // ;;; End: