dominanceCheck.h
Go to the documentation of this file.
00001 /* dominanceCheck.h
00002  */
00003 #ifndef SEARCH_DOMINANCECHECK_H
00004 #define SEARCH_DOMINANCECHECK_H
00005 
00006 #include "osl/hash/hashKeyStack.h"
00007 namespace osl
00008 {
00009   namespace search
00010   {
00011     struct DominanceCheck
00012     {
00013       enum Result { NORMAL=0, WIN, LOSE };
00020       static Result detect(const HashKeyStack& history, 
00021                            const HashKey& next_state)
00022       {
00023         const Player player = alt(next_state.turn());
00024         const PieceStand new_stand = next_state.blackStand();
00025         for (size_t i=3; i<history.size(); i+=4)
00026         {
00027           // 4手が最小のループ. 6は銀があると発生するが頻度は不明
00028           const HashKey& old_state = history.top(i);
00029           assert(old_state.turn() == next_state.turn());
00030           if (! old_state.isSameBoard(next_state))
00031             continue;
00032 
00033           const PieceStand old_stand = old_state.blackStand();
00034           if (old_stand == new_stand)
00035             return NORMAL;      // 千日手は別に検出
00036           if (old_stand.hasMoreThan(player, new_stand))
00037             return LOSE;
00038           if (new_stand.hasMoreThan(player, old_stand))
00039             return WIN;
00040         }
00041         return NORMAL;
00042       }
00043     };
00044   } // namespace search
00045 } // namespace osl
00046 
00047 
00048 #endif /* SEARCH_DOMINANCECHECK_H */
00049 // ;;; Local Variables:
00050 // ;;; mode:c++
00051 // ;;; c-basic-offset:2
00052 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines