All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ntesukiSearcher.h
Go to the documentation of this file.
1 /* ntesukiSearcher.h
2  */
3 #ifndef _NTESUKI_SEACHER_H
4 #define _NTESUKI_SEACHER_H
9 
13 
14 #include <osl/stl/vector.h>
15 
16 namespace osl
17 {
18  namespace ntesuki
19  {
20  class
22  {
23  public:
24  typedef NumEffectState State;
25 
26  private:
27  State& state;
28 
31 
34 
37 
39  unsigned int node_count;
40 
42  unsigned int read_node_limit;
43 
45  bool verbose;
46 
48  volatile int *stop_flag;
49 
52 
54  typedef std::vector<Move> moves_t;
55  moves_t moves_played;
56 
58  typedef std::vector<NtesukiRecord *> nodes_t;
59  nodes_t nodes_played;
60 
62  unsigned int max_pass;
63 
64 
65  public:
69  static bool delay_non_pass;
70  static bool ptt_invalid_defense;
71 
72  static bool delay_interpose;
73  static bool delay_nopromote;
74  static bool delay_non_attack;
75  static bool read_attack_only;
76  static bool ptt_non_attack;
77 
78  static bool ptt_siblings_fail;
79  static bool ptt_siblings_success;
80 
81  static bool ptt_uncle;
82  static bool ptt_aunt;
83 
84  static unsigned int dynamic_widening_width;
85 
86  private:
93 
96 
99 
101  double gc_ratio;
102 
103  template<class Search,Player T> class AttackHelper;
104  template<class Search,Player T> class DefenseHelper;
105  template<class Search,Player T> class CallSimulationAttack;
106  template<class Search,Player T> class CallSimulationDefense;
107  template<class Search,Player T> class CallSimulationDefenseDisproof;
108 
109  /* statistic information */
110  unsigned int blockByAttackBack;
111  unsigned int blockByPass;
112  unsigned int attack_node_count;
115  unsigned int defense_node_count;
118  unsigned int pass_count, pass_success_count;
119  unsigned int pass_attack_count, pass_attack_success_count;
120  unsigned int sibling_defense_count, sibling_defense_success_count;
121  unsigned int sibling_attack_count, sibling_attack_success_count;
122  unsigned int isshogi_defense_count, isshogi_defense_success_count;
123  unsigned int isshogi_attack_count, isshogi_attack_success_count;
124  unsigned int immediate_win, immediate_lose;
125  unsigned int attack_back_count;
126  unsigned int proof_without_inversion_count, proof_AND_count, disproof_by_inversion_count;
127 
128  public:
129  static const int NtesukiNotFound = -1;
130  static const int ReadLimitReached = -2;
131  static const int TableLimitReached = -3;
132  private:
133  static const unsigned int INITIAL_PROOF_LIMIT =
135  static const unsigned int INITIAL_DISPROOF_LIMIT =
137 
141  template <Player T>
142  NtesukiResult attack(NtesukiRecord* record,
143  const NtesukiRecord* oracle_attack,
144  const NtesukiRecord* oracle_defense,
145  unsigned int proofLimit,
146  unsigned int disproofLimit,
147  int pass_left,
148  const Move last_move);
149  template <Player T>
150  void attackWithOrder(NtesukiRecord* record,
151  const NtesukiRecord* oracle_attack,
152  const NtesukiRecord* oracle_defense,
153  unsigned int proofLimit,
154  unsigned int disproofLimit,
155  int pass_left,
156  const Move last_move);
157 
158  template <Player T>
159  NtesukiMove* selectMoveAttack(NtesukiRecord* record,
160  unsigned int& best_proof,
161  unsigned int& sum_disproof,
162  unsigned int& second_proof,
163  unsigned int& best_disproof,
164  unsigned int& step_cost,
166  const int pass_left);
167 
171  template <Player T>
172  NtesukiResult defense(NtesukiRecord* record,
173  const NtesukiRecord* oracle_attack,
174  const NtesukiRecord* oracle_defense,
175  unsigned int proofLimit,
176  unsigned int disproofLimit,
177  int pass_left,
178  const Move last_move);
179 
180 
181  template <Player T>
182  void defenseWithPlayer(NtesukiRecord* record,
183  const NtesukiRecord* oracle_attack,
184  const NtesukiRecord* oracle_defense,
185  unsigned int proofLimit,
186  unsigned int disproofLimit,
187  int pass_left,
188  const Move last_move);
189 
190  template <Player T>
191  NtesukiMove* selectMoveDefense(NtesukiRecord* record,
192  unsigned int& best_disproof,
193  unsigned int& sum_proof,
194  unsigned int& second_disproof,
195  unsigned int& best_proof,
196  unsigned int& step_cost,
198  const int pass_left,
199  const Move last_move);
200 
208  template <Player T> void simulateSiblingsSuccess(NtesukiRecord *record,
209  NtesukiRecord *record_best,
210  int pass_left,
211  unsigned int& success_count,
212  unsigned int& total_count);
213 
218  template <Player T> void simulateSiblingsFail(NtesukiRecord *record,
219  NtesukiRecord *record_best,
220  int pass_left,
221  unsigned int& success_count,
222  unsigned int& total_count);
226  template <Player T> void handleNonAttack(NtesukiRecord *record,
227  int pass_left);
231  template <Player T> void handleTonshi(NtesukiRecord *record,
232  int pass_left,
233  const Move last_move);
237  template <Player T> void handleInterpose(NtesukiRecord *record,
238  int pass_left);
239 
240  public:
241  /* ======================
242  * 外から呼ばれる関数
243  */
244  NtesukiSearcher(State& state,
246  unsigned int table_limit,
247  volatile int *stop_flag,
248  bool verbose,
249  int maxPass = NtesukiRecord::SIZE,
253  int tsumero_cost = 0,
254  int tsumero_estimate = 0,
255  double gc_ratio = 0.33);
256  ~NtesukiSearcher();
257 
258 
259  template <Player T> int search();
260 
261  int searchSlow(Player attacker, int rnl = 160000)
262  {
263  read_node_limit = rnl;
264  if (attacker == BLACK)
265  return search<BLACK>();
266  else
267  return search<WHITE>();
268  }
269 
270  NtesukiTable& getTable();
271  int getNodeCount() const { return node_count; }
272  bool exceedReadNodeLimit() const {return node_count > read_node_limit;}
273 
274  };
275  } //ntesuki
276 } //osl
277 
278 #endif /* _NTESUKI_SEACHER_H */
279 // ;;; Local Variables:
280 // ;;; mode:c++
281 // ;;; c-basic-offset:2
282 // ;;; End: