Fix gtest dependency for Travis CI
[purplehaze.git] / src / pieces.h
blob66026277b8264556623b161a358af0b428d62b52
1 /* Copyright (C) 2007-2012 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 <cassert>
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 nb_pieces(),
35 total()
37 std::fill(&positions[0][0][0],
38 &positions[0][0][0] + sizeof(positions),
39 OUT);
42 Square position(Piece p) const {
43 assert(0 <= p.index() && p.index() < 9);
44 return positions[p.color()][p.type()][p.index()];
46 Square position(Color c, PieceType t, int i) const {
47 assert(0 <= i && i < 9);
48 return positions[c][t][i];
50 void set_position(Piece p, Square s) {
51 assert(0 <= p.index() && p.index() < 9);
52 positions[p.color()][p.type()][p.index()] = s;
54 void set_position(Color c, PieceType t, int i, Square s) {
55 assert(0 <= i && i < 9);
56 positions[c][t][i] = s;
58 unsigned char count(Color c, PieceType t) const {
59 return nb_pieces[c][t];
61 unsigned char count(Color c) const {
62 return total[c];
65 // FIXME? No warning if nb < 0 or nb > 9
66 void inc_nb_pieces(Color c, PieceType t) {
67 ++nb_pieces[c][t];
68 ++total[c];
70 void dec_nb_pieces(Color c, PieceType t) {
71 --nb_pieces[c][t];
72 --total[c];
76 #endif /* !PIECESL_H */