Merge branch 'hotfix-version' into develop
[purplehaze.git] / src / moves.h
blob8760f398c88937786171b1bdf4a89c2d52766591
1 /* Copyright (C) 2007-2011 Vincent Ollivier
3 * Purple Haze is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * Purple Haze is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef MOVES_H
18 #define MOVES_H
20 #include "common.h"
21 #include "move.h"
22 #include "board.h"
23 #include "position.h"
25 typedef char Score;
27 const Score BEST_SCORE = 127;
28 const Score KILLERS_SCORE = 0;
30 const int MOVES_STATE_SIZE = 5;
31 enum MovesState : unsigned char {
32 BEST, GOOD_CAPTURES, KILLERS, BAD_CAPTURES, QUIET_MOVES, UNDEF_MOVES
35 class MoveList
37 private:
38 ExtendedMove list[MAX_PLY][MAX_BF];
39 unsigned int ply;
41 public:
42 MoveList() :
43 ply(0)
45 for (int i = 0; i < MAX_PLY; ++i) {
46 for (int j = 0; j < MAX_BF; ++j) {
47 list[i][j] = ExtendedMove();
51 void inc_ply() { ++ply; };
52 void dec_ply() { --ply; };
53 void clear() { ply = 0; };
54 ExtendedMove& operator[] (unsigned char i) { return list[ply][i]; };
57 class Moves
59 private:
60 static Score mvv_lva_scores[NB_PIECE_TYPES][NB_PIECE_TYPES];
62 MoveList& moves;
63 Position& current_position;
64 Board& board;
65 Pieces& pieces;
67 unsigned char size[MOVES_STATE_SIZE]; // Moves types counters
68 unsigned char i, n;
69 MovesState state;
70 bool use_lazy_generation;
72 public:
73 Moves(Board& b, Pieces& ps, Position& cn, MoveList& ml,
74 bool lg = true) :
75 moves(ml), current_position(cn), board(b), pieces(ps),
76 i(0), n(0),
77 state(BEST),
78 use_lazy_generation(lg)
80 moves.inc_ply(); // Increment move list internal counter
81 for (int j = 0; j < MOVES_STATE_SIZE; ++j) size[j] = 0;
84 ~Moves() {
85 moves.dec_ply(); // Decrement move list internal counter
88 void generate(MoveType mt = NULL_MOVE); // here NULL_MOVE => ALL_MOVE
89 void generate_pieces(Color c, PieceType t, MoveType mt);
90 void add(Move m, MovesState mt = UNDEF_MOVES);
91 ExtendedMove next();
92 MovesState get_state() const { return state; };
94 static void init_mvv_lva_scores();
95 Score get_mvv_lva_score(Move m);
98 // Used in divide
99 void numeric_sort();
103 #endif /* !MOVES_H */