Refactor killer moves
[purplehaze.git] / src / game.h
blob3a18ecdf5ecb2f84d7c935083e01cee765e0a7c5
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 GAME_H
18 #define GAME_H
20 #include <string>
22 #include "pieces.h"
23 #include "board.h"
24 #include "moves.h"
25 #include "tt.h"
26 #include "hashtable.h"
27 #include "time.h"
28 #include "tree.h"
29 #include "zobrist.h"
30 #include "search.h"
32 class Position;
34 class Game
36 private:
37 Zobrist zobrist;
38 Move killer_moves[MAX_PLY][MAX_KILLERS];
39 HashTable<Material> material_table;
41 public:
42 bool output_thinking;
43 unsigned int nodes_count; // Used in search
44 Pieces pieces;
45 Board board;
46 Tree tree;
47 Time time;
48 Transpositions tt;
49 MoveList search_moves;
50 Game();
51 void add_piece(Color c, PieceType t, Square s);
52 void del_piece(Color c, PieceType t, int i);
53 void del_piece(Piece p) {
54 del_piece(p.color(), p.type(), p.index());
57 void new_position();
58 void del_position();
59 Position& current_position() {
60 return tree.top();
63 void init(std::string fen);
65 bool is_check(Color c) const {
66 Square s = pieces.position(c, KING, 0);
67 return board.is_attacked_by(!c, s, pieces);
70 void make_move(Move m);
71 void undo_move(Move m);
72 bool is_legal(Move m);
73 bool is_dangerous(Move m);
75 // Search
76 unsigned long long int perft(unsigned int depth);
78 int quiescence(int alpha, int beta, int depth, const int ply);
80 template<NodeType node_type>
81 int search(int alpha, int beta, int depth, const int ply);
83 Move root(int max_depth);
85 // Killer Moves
86 void clear_killers();
88 Move killer(int depth, int index) {
89 return killer_moves[depth][index];
92 Move (&killers(const int depth))[MAX_KILLERS] {
93 return killer_moves[depth];
95 void set_killer(const Move move, const int depth);
96 bool is_killer(const Move move, const int depth) {
97 return (move == killer_moves[depth][0] ||
98 move == killer_moves[depth][1]);
101 // Position's evaluation
102 void init_eval();
103 int eval(int alpha, int beta);
104 int material_eval();
105 int position_eval();
107 // Output
108 void print_thinking_header();
109 void print_thinking(int depth, int score, Move m);
110 std::string output_pv(int depth, int score, Move m);
111 std::string output_move(Move m);
112 std::string output_square(Square s) {
113 return output_square(board.file(s), board.rank(s));
115 std::string output_square(File f, Rank r);
116 void print_tt_stats();
117 std::string debug_move(Move m);
120 #endif /* !GAME_H */