ntesukiMove.h
Go to the documentation of this file.
00001 /* ntesukiMove.h
00002  */
00003 #ifndef _NTESUKIMOVE_H
00004 #define _NTESUKIMOVE_H
00005 
00006 #include "osl/move.h"
00007 #include "osl/ntesuki/ntesukiExceptions.h"
00008 
00009 namespace osl
00010 {
00011   namespace ntesuki
00012   {
00018     class NtesukiMove
00019     {
00020       enum Flags
00021       {
00022         NONE = 0,
00023         /* 2^0 */
00024         CHECK_FLAG = 1,                 
00025         /* 2^1 */
00026         PAWN_DROP_CHECKMATE_FLAG = 2,   
00027         /* 2^2 */
00028         /* 4 not used */
00029         /* 2^3 */
00030         IMMEDIATE_CHECKMATE = 8,        
00031         /* 2^4 */
00032         TO_OLDER_CHILD = 16,            
00033         /* 2^5 */
00034         NOPROMOTE = 32,                 
00035         /* 2^6 */
00036         INTERPOSE = 64,                 
00037         /* 2^7 */
00038         ATTACK_FLAG = 128,              
00039         /* 2^8 */
00040         BY_SIMULATION = 256,            
00041         /* 2^9 */
00042         LAME_LONG = 512,
00043         /* 2^10 */
00044         /* 2^11 */
00045         /* 2^12 */
00046         /* 2^13 */
00047         /* 2^14 */
00048         /* 2^15 */
00049         WHITE_SHIFT = 4,
00050         IS_SUCCESS_SHIFT = 16,          
00051         /* 16-19 BLACK SUCCESS */
00052         IS_SUCCESS_BLACK_SHIFT = IS_SUCCESS_SHIFT,
00053         /* 20-23 WHITE SUCCESS */
00054         IS_SUCCESS_WHITE_SHIFT = IS_SUCCESS_SHIFT + WHITE_SHIFT,
00055         IS_SUCCESS_BLACK_BASE = 1 << IS_SUCCESS_BLACK_SHIFT,
00056         IS_SUCCESS_WHITE_BASE = 1 << IS_SUCCESS_WHITE_SHIFT,
00057         IS_SUCCESS_BLACK_MASK = 0xf * IS_SUCCESS_BLACK_BASE,
00058         IS_SUCCESS_WHITE_MASK = 0xf * IS_SUCCESS_WHITE_BASE,
00059         IS_FAIL_SHIFT = 24,             
00060         /* 24-27 BLACK FAIL */
00061         IS_FAIL_BLACK_SHIFT = IS_FAIL_SHIFT,
00062         /* 28-31 WHITE FAIL */
00063         IS_FAIL_WHITE_SHIFT = IS_FAIL_SHIFT + WHITE_SHIFT,
00064         IS_FAIL_BLACK_BASE = 1 << IS_FAIL_SHIFT,
00065         IS_FAIL_WHITE_BASE = 1 << (IS_FAIL_SHIFT + WHITE_SHIFT),
00066         IS_FAIL_BLACK_MASK = 0xf * IS_FAIL_BLACK_BASE,
00067         IS_FAIL_WHITE_MASK = 0xfLL * IS_FAIL_WHITE_BASE,
00068       };
00069 
00070       static std::string FlagsStr[];
00071       template <Player P>
00072       int is_success_flag(int pass_left) const;
00073       template <Player P>
00074       int is_fail_flag(int pass_left) const;
00075 
00076       osl::Move move;
00077       int flags;
00078       int order;
00079     public:
00080       unsigned short h_a_proof, h_a_disproof;   // 4 byte
00081       unsigned short h_d_proof, h_d_disproof;   // 4 byte
00082       
00083     public:
00084       NtesukiMove();
00085       NtesukiMove(osl::Move m);
00086       NtesukiMove(osl::Move m, Flags f);
00087       NtesukiMove(const NtesukiMove&);
00088       ~NtesukiMove();
00089       NtesukiMove operator=(const NtesukiMove&);
00090 
00091       /* static methods */
00092       static NtesukiMove INVALID();
00093 
00094       /* about the state of the node
00095        */
00096       /* if it is a check move */
00097       void setCheck();
00098       bool isCheck() const;
00099 
00100       /* if it is a check move */
00101       void setOrder(int o);
00102       int getOrder() const;
00103 
00104       /* interpose */
00105       void setInterpose();
00106       bool isInterpose() const;
00107 
00108       /* long move with no specific meaning */
00109       void setLameLong();
00110       bool isLameLong() const;
00111 
00112       /* by simulation */
00113       void setBySimulation();
00114       bool isBySimulation() const;
00115 
00116       /* nopromote */
00117       void setNoPromote();
00118       bool isNoPromote() const;
00119 
00120       /* if it is a move to an child with less depth */
00121       void setToOld();
00122       bool isToOld() const;
00123 
00124       /* if it is a immidiate checkmate move */
00125       template<Player P>
00126       void setImmediateCheckmate();
00127       bool isImmediateCheckmate() const;
00128 
00129       /* if it is a success/fail move */
00130       template<Player P>
00131       void setCheckmateSuccess(int pass_left);
00132       template<Player P>
00133       bool isCheckmateSuccess(int pass_left) const;
00134       bool isCheckmateSuccessSlow(Player P, int pass_left) const;
00135 
00136       template<Player P>
00137       void setCheckmateFail(int pass_left);
00138       template<Player P>
00139       bool isCheckmateFail(int pass_left) const;
00140       bool isCheckmateFailSlow(Player P, int pass_left) const;
00141 
00142       /* if it is a pawn drop checkmate move */
00143       void setPawnDropCheckmate();
00144       bool isPawnDropCheckmate() const;
00145 
00146       /* estimates used before the node after the move is expanded */
00147       void setHEstimates(unsigned short p_a, unsigned short d_a,
00148                          unsigned short p_d, unsigned short d_d);
00149       void setCEstimates(unsigned short p, unsigned short d);
00150 
00151       /* about the move itself */
00152       bool isValid() const;
00153       bool isInvalid() const;
00154       bool isNormal() const;
00155       bool isPass() const;
00156       bool isDrop() const;
00157       Square to() const;
00158       Ptype ptype() const;
00159       Move getMove() const;
00160 
00161       /* equality, only the equality of the move is checked
00162        * (the flags are not considered) */
00163       bool operator==(const NtesukiMove& rhs) const;
00164       bool operator!=(const NtesukiMove& rhs) const;
00165 
00166       /* output to stream */
00167       void flagsToStream(std::ostream& os) const;
00168       friend std::ostream& operator<<(std::ostream& os, const NtesukiMove& move);
00169     };
00170 
00171   }// ntesuki
00172 }// osl
00173 #endif /* _NTESUKIMOVE_H */
00174 // ;;; Local Variables:
00175 // ;;; mode:c++
00176 // ;;; c-basic-offset:2
00177 // ;;; coding:utf-8
00178 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines