Overload Board's subscript operator
[purplehaze.git] / src / moves.h
blob634310012b3fffa45f72378d80d14dfd1b69a885
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"
23 class Board;
24 class Pieces;
25 class Position;
27 typedef char Score;
29 const Score BEST_SCORE = 127;
30 const Score KILLERS_SCORE = 0;
32 const int MOVES_STATE_SIZE = 5;
33 enum MovesState : unsigned char {
34 BEST, GOOD_CAPTURES, KILLERS, BAD_CAPTURES, QUIET_MOVES, UNDEF_MOVES
37 class MoveList
39 private:
40 ExtendedMove list[MAX_PLY][MAX_BF];
41 unsigned int ply;
43 public:
44 MoveList() :
45 ply(0)
47 for (int i = 0; i < MAX_PLY; ++i) {
48 for (int j = 0; j < MAX_BF; ++j) {
49 list[i][j] = ExtendedMove();
53 void inc_ply() {
54 ++ply;
56 void dec_ply() {
57 --ply;
59 void clear() {
60 ply = 0;
62 ExtendedMove& operator[] (unsigned char i) {
63 return list[ply][i];
67 class Moves
69 private:
70 static Score mvv_lva_scores[NB_PIECE_TYPES][NB_PIECE_TYPES];
72 MoveList& moves;
73 const Position& current_position;
74 const Board& board;
75 const Pieces& pieces;
77 unsigned char size[MOVES_STATE_SIZE]; // Moves types counters
78 unsigned char i, n;
79 MovesState generation_state;
80 bool use_lazy_generation;
82 public:
83 Moves(const Board& b, const Pieces& ps, const Position& cn,
84 MoveList& ml, bool lg = true) :
85 moves(ml), current_position(cn), board(b), pieces(ps),
86 i(0), n(0),
87 generation_state(BEST),
88 use_lazy_generation(lg)
90 moves.inc_ply(); // Increment move list internal counter
91 for (int j = 0; j < MOVES_STATE_SIZE; ++j) size[j] = 0;
94 ~Moves() {
95 moves.dec_ply(); // Decrement move list internal counter
98 void generate(MoveType mt = NULL_MOVE); // here NULL_MOVE => ALL_MOVE
99 void generate_pieces(Color c, PieceType t, MoveType mt);
100 void add(Move m, MovesState mt = UNDEF_MOVES);
101 ExtendedMove next();
102 MovesState state() const {
103 return generation_state;
106 static void init_mvv_lva_scores();
107 Score get_mvv_lva_score(Move m);
110 // Used in divide
111 void numeric_sort();
115 #endif /* !MOVES_H */