moveGenerator.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
moveGenerator.h
Go to the documentation of this file.
1 /* moveGenerator.h
2 */
3 #ifndef OSL_MOVEGENERATOR_H
4 #define OSL_MOVEGENERATOR_H
5
6 #include "osl/search/simpleHashRecord.h"
7 #include "osl/search/searchState2.h"
8 #include "osl/rating/ratingEnv.h"
9 #include "osl/progress/progress32.h"
10 #include "osl/container/moveLogProbVector.h"
11 #include "osl/container/moveStack.h"
12 #include "osl/misc/carray.h"
13 #include "osl/misc/carray2d.h"
14 #include "osl/misc/cstdint.h"
15
16 namespace osl
17 {
18 namespace search
19 {
20 namespace analyzer
21 {
22 class CategoryMoveVector;
23 }
24 class SearchState2;
25 class MoveMarker
26 {
27 typedef uint8_t value_t;
28 CArray2d<value_t,Offset::BOARD_HEIGHT*9,Piece::SIZE*2+PTYPE_SIZE> marker;
29 value_t cur;
30 public:
31 MoveMarker();
32 void clear();
33 static unsigned int pieceIndex(const NumEffectState& state, Move m)
34 {
35 if (m.isPass() || m.isDrop())
36 return Piece::SIZE*2+m.ptype();
37 int base = state.pieceOnBoard(m.from()).number();
38 if (m.isPromotion())
39 return base+ Piece::SIZE;
40 return base;
41 }
42 static unsigned int toIndex(Move m)
43 {
44 return m.to().index()-Square::onBoardMin().index();
45 }
46 void registerMove(const NumEffectState& state, Move m)
47 {
48 marker(toIndex(m), pieceIndex(state,m)) = cur;
49 }
50 bool registerIfNew(const NumEffectState& state, Move m);
51 bool registered(const NumEffectState& state, Move m) const;
52 };
53 class MoveGenerator
54 {
55 enum State {
56 INITIAL, KING_ESCAPE, TAKE_BACK, BREAK_THREATMATE, CAPTURE, TACTICAL_FINISH,
57 TESUJI, ALL, FINISH
58 };
59 typedef void (MoveGenerator::*generator_t)(const SearchState2&);
60 static const CArray2d<generator_t, 2, FINISH> Generators;
61 static const CArray<const char *, FINISH> GeneratorNames;
62 MoveLogProbVector moves;
63 int cur_state;
64 size_t cur_index;
65 const SimpleHashRecord *record;
66 int limit;
67 int tried;
68 MoveMarker marker;
69 RatingEnv env;
70 Progress32 progress;
71 Move eval_suggestion;
72 #ifndef MINIMAL
73 bool in_quiesce;
74 #endif
75 bool in_pv;
76 public:
77 MoveGenerator();
78 template <class EvalT>
79 void init(int limit, const SimpleHashRecord *record, const EvalT&,
80 const NumEffectState&, bool in_pv, Move hash_move, bool quiesce=false);
82 template <Player P>
83 const MoveLogProb nextTacticalMove(const SearchState2& state)
84 {
85 assert(cur_state < TACTICAL_FINISH);
86 if (cur_index < moves.size()) {
87 ++tried;
88 return moves[cur_index++];
89 }
90 return nextTacticalMoveWithGeneration<P>(state);
91 }
92 template <Player P>
93 const MoveLogProb nextMove(const SearchState2& state)
94 {
95 assert(cur_state >= TACTICAL_FINISH);
96 if (cur_index < moves.size()) {
97 ++tried;
98 return moves[cur_index++];
99 }
100 if (cur_state < FINISH)
101 return nextMoveWithGeneration<P>(state);
102 return MoveLogProb();
103 }
104
106 void registerMove(const NumEffectState& state, Move m)
107 {
108 ++tried;
109 if (! m.isNormal())
110 return;
111 marker.registerMove(state, m);
112 }
113
114 int triedMoves() const { return tried; }
115 const PieceMask& myPins() const { return env.my_pin; }
116 void dump() const;
117
118 // construct直後に呼ぶこと
119 void generateAll(Player P, const SearchState2& state,
120 analyzer::CategoryMoveVector&);
121 template <Player P>
122 void generateAll(const SearchState2&, MoveLogProbVector&);
123 void generateAll(Player P, const SearchState2& state, MoveLogProbVector& out);
124
125 const MoveLogProbVector& generated() const { return moves; }
126 static int captureValue(Ptype);
127 template <Player P>
128 void quiesceCapture(const NumEffectState&, Square);
129 private:
130 template <Player P>
131 const MoveLogProb nextMoveWithGeneration(const SearchState2&) ;
132 template <Player P>
133 const MoveLogProb nextTacticalMoveWithGeneration(const SearchState2&) ;
134 template <Player P>
135 void generateKingEscape(const SearchState2& state);
136 template <Player P>
137 void generateTakeBack(const SearchState2& state);
138 template <Player P>
139 void generateBreakThreatmate(const SearchState2& state);
140 template <Player P>
141 void generateCapture(const SearchState2& state);
142 template <Player P>
143 void generateTesuji(const SearchState2& state);
144 template <Player P>
145 void generateAllExp(const SearchState2& state);
146 template <Player P>
147 void generateAll(const SearchState2& state);
148 template <Player P>
149 void addCapture(const NumEffectState&, const RatingEnv&, const MoveVector&);
150 public:
152 static void initOnce();
153 };
154 }
155 }
156
157
158 #endif /* OSL_MOVEGENERATOR_H */
159 // ;;; Local Variables:
160 // ;;; mode:c++
161 // ;;; c-basic-offset:2
162 // ;;; coding:utf-8
163 // ;;; End: