00001
00002
00003 #ifndef _MOVE_STACK_REJECTIONS_H
00004 #define _MOVE_STACK_REJECTIONS_H
00005 #include "osl/state/numEffectState.h"
00006 #include "osl/container/moveStack.h"
00007 #include "osl/misc/carray.h"
00008 #include <iosfwd>
00009
00010 namespace osl
00011 {
00012 namespace search
00013 {
00018 struct OnBoardElement {
00019 short posPtypeO;
00020 OnBoardElement() {}
00021 OnBoardElement(Position pos_,PtypeO ptypeO_){
00022 posPtypeO=makePosPtypeO(pos_,ptypeO_);
00023 }
00024 static short makePosPtypeO(Position pos,PtypeO ptypeO)
00025 {
00026 return static_cast<short>(pos.uintValue()+(ptypeO<<8));
00027 }
00028 Position pos() const{
00029 return Position::makeDirect(posPtypeO&0xff);
00030 }
00031 PtypeO ptypeO() const{
00032 return static_cast<PtypeO>(posPtypeO>>8);
00033 }
00034 };
00039 struct StandElements {
00040 union {
00041 CArray<char,8> c8;
00042 unsigned long long l8;
00043 } v;
00044 StandElements() { v.l8=0x8080808080808080ull; }
00048 void add(Ptype ptype){
00049 assert(ptype>=PTYPE_BASIC_MIN);
00050 v.c8[ptype-PTYPE_BASIC_MIN]++;
00051 }
00055 void sub(Ptype ptype){
00056 assert(ptype>=PTYPE_BASIC_MIN);
00057 v.c8[ptype-PTYPE_BASIC_MIN]--;
00058 }
00059 bool isZero() const{
00060 return v.l8==0x8080808080808080ull;
00061 }
00062 bool gtZero() const{
00063 return !isZero() && geZero();
00064 }
00065 bool geZero() const{
00066 return (v.l8&0x8080808080808080ull)==0x8080808080808080ull;
00067 }
00068 bool gegtZero(bool notRejectSennichite) const{
00069 if(notRejectSennichite) return gtZero();
00070 else return geZero();
00071 }
00072 };
00080 struct StateElements {
00081 FixedCapacityVector<OnBoardElement,32> myOnboardPlus;
00082 FixedCapacityVector<OnBoardElement,32> opOnboardPlus;
00083 FixedCapacityVector<OnBoardElement,64> myOnboardMinus;
00084 FixedCapacityVector<OnBoardElement,64> opOnboardMinus;
00085 StandElements stand;
00086 public:
00087 StateElements() {
00088 }
00089 void clear() {
00090 }
00095 void addStand(Ptype ptype);
00100 void subStand(Ptype ptype);
00104 void addMyBoard(Position pos,PtypeO ptypeO);
00105 void subMyBoard(Position pos,PtypeO ptypeO);
00106 void addOpBoard(Position pos,PtypeO ptypeO);
00107 void subOpBoard(Position pos,PtypeO ptypeO);
00111 void addMyMove(Move move);
00115 void addOpMove(Move move);
00119 bool isLoop() const{
00120 return myOnboardPlus.size()==0 && opOnboardPlus.size()==0 &&
00121 myOnboardMinus.size()==0 && opOnboardMinus.size()==0;
00122 }
00126 template<Player P>
00127 bool validSimpleMove(NumEffectState const& state,OnBoardElement const& fromElement,OnBoardElement const& toElement) const;
00132 template<Player P>
00133 bool validSimpleMove(NumEffectState const& state,OnBoardElement const& fromElement,OnBoardElement const& toElement,Move lastMove) const;
00137 template<Player P>
00138 bool validCaptureMove(NumEffectState const& state, OnBoardElement const& fromElement,OnBoardElement const& toElement,OnBoardElement const& captureElement) const;
00143 template<Player P>
00144 bool validCaptureMove(NumEffectState const& state, OnBoardElement const& fromElement,OnBoardElement const& toElement,OnBoardElement const& captureElement,Move lastMove) const;
00161 template<Player P>
00162 bool canReject(NumEffectState const& state,bool notRejectSennichite,bool notRootMove,Move lastMove) const;
00163 };
00164 std::ostream& operator<<(std::ostream&,OnBoardElement const&);
00165 std::ostream& operator<<(std::ostream&,StandElements const&);
00166 std::ostream& operator<<(std::ostream&,StateElements const&);
00167 class MoveStackRejections
00168 {
00169 public:
00179 template<Player P>
00180 static bool probe(NumEffectState const& state,MoveStack const& history,int curDepth,Move const& m,int alpha, int checkCountOfAltP);
00181 };
00182 }
00183 }
00184 #endif