All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ntesukiTable.tcc
Go to the documentation of this file.
1 /* ntesukiTable.tcc
2  */
5 #include "osl/apply_move/applyMoveWithPath.h"
6 #include <iterator>
7 
8 using namespace osl;
9 using namespace osl::ntesuki;
10 
11 template<class Search, class F> class
13 {
14  Search* searcher;
15  F& func;
18 public:
19  DoUndoMoveHelper(Search* searcher,
20  F& func,
21  NumEffectState& state,
22  NtesukiRecord *child)
23  : searcher(searcher), state(state), child(child)
24  {
25  }
26 
27  void operator()(Square last_to)
28  {
29  (*searcher).template forEachRecordFrom<F>(func, state, child);
30  }
31 };
32 
33 
34 template <class F>
35 void
37 forEachRecord(F& func)
38 {
39  for (iterator it = begin(); it != end(); ++it)
40  {
41  for (NtesukiRecord::RecordList::iterator p = it->second.begin();
42  p != it->second.end(); ++p)
43  {
44  NtesukiRecord *r = &(*p);
45  func(r);
46  }
47  }
48 }
49 
50 template <class F>
51 void
54  NumEffectState& state,
55  NtesukiRecord *record)
56 {
58  NtesukiMoveList all_moves;
59  mg.generateSlow(state.turn(), state, all_moves);
60 
61  func.enter(record);
62 
63  std::vector<NtesukiMove> moves;
64  std::copy(all_moves.begin(), all_moves.end(),
65  std::back_insert_iterator<std::vector<NtesukiMove> >(moves));
66  typename F::Compare c;
67  std::sort(moves.begin(), moves.end(), c);
68  for (std::vector<NtesukiMove>::const_iterator it = moves.begin();
69  it != moves.end(); ++it)
70  {
71  const NtesukiMove& m = *it;
72  NtesukiRecord *child = find(record->key.newHashWithMove(m.getMove()));
73  if (child)
74  {
75  if (func.withChildMove(m, child))
76  {
77  DoUndoMoveHelper<Table, F> helper(func, state, child);
78  ApplyMoveOfTurn::doUndoMove(state, m.getMove(), helper);
79  }
80  }
81  else
82  {
83  func.noChildMove(m);
84  }
85  }
86  func.exit();
87 }
88 
89 template <class F>
90 void
93 {
94  if (rootState.get() == NULL)
95  {
96  throw RootStateNotSet();
97  }
98 
99  NumEffectState state(*rootState);
100  forEachRecordFrom<F>(func, state, root);
101 }
102 // ;;; Local Variables:
103 // ;;; mode:c++
104 // ;;; c-basic-offset:2
105 // ;;; End: