Add Game::is_dangerous() for Futility Pruning
[purplehaze.git] / src / pieces.h
blob837e6e11df999ba1c7bd207471ca12465678ada7
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 PIECES_H
18 #define PIECES_H
20 #include <assert.h>
22 #include "common.h"
23 #include "piece.h"
25 class Pieces
27 private:
28 Square positions[2][7][9];
29 unsigned char nb_pieces[2][7];
30 unsigned char total[2];
32 public:
33 Pieces();
34 Square get_position(Piece p) const {
35 return positions[p.get_color()][p.get_type()][p.get_index()];
37 Square get_position(Color c, PieceType t, int i) const {
38 assert(0 <= i && i < 9);
39 return positions[c][t][i];
41 void set_position(Piece p, Square s) {
42 positions[p.get_color()][p.get_type()][p.get_index()] = s;
44 void set_position(Color c, PieceType t, int i, Square s) {
45 assert(0 <= i && i < 9);
46 positions[c][t][i] = s;
48 unsigned char count(Color c, PieceType t) const {
49 return nb_pieces[c][t];
51 unsigned char count(Color c) const {
52 return total[c];
55 // FIXME? No warning if nb < 0 or nb > 9
56 void inc_nb_pieces(Color c, PieceType t) {
57 ++nb_pieces[c][t];
58 ++total[c];
60 void dec_nb_pieces(Color c, PieceType t) {
61 --nb_pieces[c][t];
62 --total[c];
66 #endif /* !PIECESL_H */