dualThreatmateState.h
Go to the documentation of this file.
00001 /* dualThreatmateState.h
00002  */
00003 #ifndef OSL_SEARCH__DUALTHREATMATESTATE_H
00004 #define OSL_SEARCH__DUALTHREATMATESTATE_H
00005 
00006 #include "osl/search/threatmateState.h"
00007 #include "osl/effect_util/sendOffSquare.h"
00008 #include <iosfwd>
00009 
00010 namespace osl
00011 {
00012   namespace search
00013   {
00014     class DualThreatmateState
00015     {
00016       CArray<Move,2> threatmate_move;
00017       CArray<ThreatmateState,2> king_status;
00018       ThreatmateState& wstatus(Player king)
00019       {
00020         return king_status[king];
00021       }
00022     public:
00024       mutable SendOffSquare::SendOff8 sendoffs;
00025 #ifdef OSL_SMP
00026       volatile
00027 #endif
00028       struct Flags {
00029         bool is_king_in_check:4;
00030         char static_value_type:4;
00031       } flags;
00032       explicit DualThreatmateState(ThreatmateState::Status b=ThreatmateState::UNKNOWN,
00033                                    ThreatmateState::Status w=ThreatmateState::UNKNOWN) 
00034         : sendoffs(SendOffSquare::invalidData())
00035       {
00036         wstatus(BLACK) = b;
00037         wstatus(WHITE) = w;
00038         flags.is_king_in_check = false;
00039         flags.static_value_type = 0;
00040       }
00041       const ThreatmateState& status(Player king) const
00042       {
00043         return king_status[king];
00044       }
00045       void setThreatmate(Player king, Move m) { 
00046         assert(m.isNormal());
00047         wstatus(king).setThreatmate(ThreatmateState::THREATMATE);
00048         threatmate_move[king] = m;
00049       }
00050 
00051       bool isThreatmate(Player king) const { 
00052         return status(king).isThreatmate();
00053       }
00054       const Move threatmateMove(Player king) const { 
00055         return threatmate_move[king];
00056       }
00057       bool maybeThreatmate(Player king) const { 
00058         return status(king).maybeThreatmate();
00059       }
00060       bool mayHaveCheckmate(Player king) const {
00061         return status(king).mayHaveCheckmate();
00062       }
00063       void updateInLock(Player turn, const DualThreatmateState *parent, bool in_check)
00064       {
00065         if (parent)
00066         {
00067           if (! maybeThreatmate(turn))
00068             wstatus(turn).update(&parent->status(turn), in_check);
00069           if (! mayHaveCheckmate(alt(turn)))
00070             wstatus(alt(turn)).update(&parent->status(alt(turn)), in_check);
00071         }
00072       }
00073     };
00074     std::ostream& operator<<(std::ostream&, DualThreatmateState);
00075   }
00076 } // namespace osl
00077 
00078 #endif /* OSL_SEARCH__DUALTHREATMATESTATE_H */
00079 // ;;; Local Variables:
00080 // ;;; mode:c++
00081 // ;;; c-basic-offset:2
00082 // ;;; coding:utf-8
00083 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines