Rev 96 | Rev 169 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 96 | Rev 154 | ||
---|---|---|---|
Line 24... | Line 24... | ||
24 | #include <algorithm> // For std::max |
24 | #include <algorithm> // For std::max |
25 | #include <cstring> // For std::memset |
25 | #include <cstring> // For std::memset |
26 | 26 | ||
27 | #include "movegen.h" |
27 | #include "movegen.h" |
28 | #include "position.h" |
28 | #include "position.h" |
29 | #include "search.h" |
- | |
30 | #include "types.h" |
29 | #include "types.h" |
31 | 30 | ||
32 | 31 | ||
33 | /// The Stats struct stores moves statistics. According to the template parameter |
32 | /// The Stats struct stores moves statistics. According to the template parameter |
34 | /// the class can store History and Countermoves. History records how often |
33 | /// the class can store History and Countermoves. History records how often |
Line 43... | Line 42... | ||
43 | static const Value Max = Value(1 << 28); |
42 | static const Value Max = Value(1 << 28); |
44 | 43 | ||
45 | const T* operator[](Piece pc) const { return table[pc]; } |
44 | const T* operator[](Piece pc) const { return table[pc]; } |
46 | T* operator[](Piece pc) { return table[pc]; } |
45 | T* operator[](Piece pc) { return table[pc]; } |
47 | void clear() { std::memset(table, 0, sizeof(table)); } |
46 | void clear() { std::memset(table, 0, sizeof(table)); } |
48 | - | ||
49 | void update(Piece pc, Square to, Move m) { |
47 | void update(Piece pc, Square to, Move m) { table[pc][to] = m; } |
50 | - | ||
51 | if (m != table[pc][to]) |
- | |
52 | table[pc][to] = m; |
- | |
53 | } |
- | |
54 | - | ||
55 | void update(Piece pc, Square to, Value v) { |
48 | void update(Piece pc, Square to, Value v) { |
56 | 49 | ||
57 | if (abs(int(v)) >= 324) |
50 | if (abs(int(v)) >= 324) |
58 | return; |
51 | return; |
59 | 52 | ||
60 | table[pc][to] -= table[pc][to] * abs(int(v)) / (CM ? |
53 | table[pc][to] -= table[pc][to] * abs(int(v)) / (CM ? 936 : 324); |
61 | table[pc][to] += int(v) * |
54 | table[pc][to] += int(v) * 32; |
62 | } |
55 | } |
63 | 56 | ||
64 | private: |
57 | private: |
65 | T table[PIECE_NB][SQUARE_NB]; |
58 | T table[PIECE_NB][SQUARE_NB]; |
66 | }; |
59 | }; |
67 | 60 | ||
68 | typedef Stats<Move> MoveStats; |
61 | typedef Stats<Move> MoveStats; |
69 | typedef Stats<Value, false> HistoryStats; |
62 | typedef Stats<Value, false> HistoryStats; |
70 | typedef Stats<Value, true> CounterMoveStats; |
63 | typedef Stats<Value, true> CounterMoveStats; |
71 | typedef Stats<CounterMoveStats> CounterMoveHistoryStats; |
64 | typedef Stats<CounterMoveStats> CounterMoveHistoryStats; |
- | 65 | ||
- | 66 | struct FromToStats { |
|
- | 67 | ||
- | 68 | Value get(Color c, Move m) const { return table[c][from_sq(m)][to_sq(m)]; } |
|
- | 69 | void clear() { std::memset(table, 0, sizeof(table)); } |
|
- | 70 | void update(Color c, Move m, Value v) { |
|
- | 71 | ||
- | 72 | if (abs(int(v)) >= 324) |
|
- | 73 | return; |
|
- | 74 | ||
- | 75 | Square from = from_sq(m); |
|
- | 76 | Square to = to_sq(m); |
|
- | 77 | ||
- | 78 | table[c][from][to] -= table[c][from][to] * abs(int(v)) / 324; |
|
- | 79 | table[c][from][to] += int(v) * 32; |
|
- | 80 | } |
|
- | 81 | ||
- | 82 | private: |
|
- | 83 | Value table[COLOR_NB][SQUARE_NB][SQUARE_NB]; |
|
- | 84 | }; |
|
72 | 85 | ||
73 | 86 | ||
74 | /// MovePicker class is used to pick one pseudo legal move at a time from the |
87 | /// MovePicker class is used to pick one pseudo legal move at a time from the |
75 | /// current position. The most important method is next_move(), which returns a |
88 | /// current position. The most important method is next_move(), which returns a |
76 | /// new pseudo legal move each time it is called, until there are no moves left, |
89 | /// new pseudo legal move each time it is called, until there are no moves left, |
77 | /// when MOVE_NONE is returned. In order to improve the efficiency of the alpha |
90 | /// when MOVE_NONE is returned. In order to improve the efficiency of the alpha |
78 | /// beta algorithm, MovePicker attempts to return the moves which are most likely |
91 | /// beta algorithm, MovePicker attempts to return the moves which are most likely |
79 | /// to get a cut-off first. |
92 | /// to get a cut-off first. |
- | 93 | namespace Search { struct Stack; } |
|
80 | 94 | ||
81 | class MovePicker { |
95 | class MovePicker { |
82 | public: |
96 | public: |
83 | MovePicker(const MovePicker&) = delete; |
97 | MovePicker(const MovePicker&) = delete; |
84 | MovePicker& operator=(const MovePicker&) = delete; |
98 | MovePicker& operator=(const MovePicker&) = delete; |
85 | 99 | ||
86 | MovePicker(const Position&, Move, |
100 | MovePicker(const Position&, Move, Value); |
87 | MovePicker(const Position&, Move, |
101 | MovePicker(const Position&, Move, Depth, Square); |
88 | MovePicker(const Position&, Move, Depth, |
102 | MovePicker(const Position&, Move, Depth, Search::Stack*); |
89 | 103 | ||
90 | Move next_move(); |
104 | Move next_move(); |
91 | 105 | ||
92 | private: |
106 | private: |
93 | template<GenType> void score(); |
107 | template<GenType> void score(); |
94 | void generate_next_stage(); |
- | |
95 | ExtMove* begin() { return |
108 | ExtMove* begin() { return cur; } |
96 | ExtMove* end() { return endMoves; } |
109 | ExtMove* end() { return endMoves; } |
97 | 110 | ||
98 | const Position& pos; |
111 | const Position& pos; |
99 | const HistoryStats& history; |
- | |
100 | const CounterMoveStats* counterMoveHistory; |
- | |
101 | Search::Stack* ss; |
112 | const Search::Stack* ss; |
102 | Move countermove; |
113 | Move countermove; |
103 | Depth depth; |
114 | Depth depth; |
104 | Move ttMove; |
115 | Move ttMove; |
105 | ExtMove killers[3]; |
- | |
106 | Square recaptureSquare; |
116 | Square recaptureSquare; |
107 | Value threshold; |
117 | Value threshold; |
108 | int stage; |
118 | int stage; |
109 | ExtMove * |
119 | ExtMove *cur, *endMoves, *endBadCaptures; |
110 | ExtMove moves[MAX_MOVES] |
120 | ExtMove moves[MAX_MOVES]; |
111 | }; |
121 | }; |
112 | 122 | ||
113 | #endif // #ifndef MOVEPICK_H_INCLUDED |
123 | #endif // #ifndef MOVEPICK_H_INCLUDED |