All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
dominanceCheck.h
Go to the documentation of this file.
1 /* dominanceCheck.h
2  */
3 #ifndef SEARCH_DOMINANCECHECK_H
4 #define SEARCH_DOMINANCECHECK_H
5 
7 namespace osl
8 {
9  namespace search
10  {
12  {
13  enum Result { NORMAL=0, WIN, LOSE };
20  static Result detect(const HashKeyStack& history,
21  const HashKey& next_state)
22  {
23  const Player player = alt(next_state.turn());
24  const PieceStand new_stand = next_state.blackStand();
25  for (size_t i=3; i<history.size(); i+=4)
26  {
27  // 4手が最小のループ. 6は銀があると発生するが頻度は不明
28  const HashKey& old_state = history.top(i);
29  assert(old_state.turn() == next_state.turn());
30  if (! old_state.isSameBoard(next_state))
31  continue;
32 
33  const PieceStand old_stand = old_state.blackStand();
34  if (old_stand == new_stand)
35  return NORMAL; // 千日手は別に検出
36  if (old_stand.hasMoreThan(player, new_stand))
37  return LOSE;
38  if (new_stand.hasMoreThan(player, old_stand))
39  return WIN;
40  }
41  return NORMAL;
42  }
43  };
44  } // namespace search
45 } // namespace osl
46 
47 
48 #endif /* SEARCH_DOMINANCECHECK_H */
49 // ;;; Local Variables:
50 // ;;; mode:c++
51 // ;;; c-basic-offset:2
52 // ;;; End: