Add Game::is_dangerous() for Futility Pruning
[purplehaze.git] / src / game.h
blob72e106b3ac30d8ec282a7f4eb3b51dfbbc95e223
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 "position.h"
26 #include "tt.h"
27 #include "hashtable.h"
28 #include "time.h"
29 #include "tree.h"
30 #include "zobrist.h"
31 #include "search.h"
33 class Game
35 private:
36 Zobrist zobrist;
37 Move killer_moves[MAX_PLY][MAX_KILLERS];
38 HashTable<int> material_table;
40 public:
41 bool output_thinking;
42 unsigned int nodes_count; // Used in search
43 Pieces pieces;
44 Board board;
45 Tree tree;
46 Time time;
47 Transpositions tt;
48 MoveList search_moves;
49 Game();
50 void add_piece(Color c, PieceType t, Square s);
51 void del_piece(Color c, PieceType t, int i);
52 void del_piece(Piece p) {
53 del_piece(p.get_color(), p.get_type(), p.get_index());
56 void new_position();
57 void del_position();
58 Position& current_position() { return tree.top(); };
60 void init(std::string fen);
62 bool is_check(Color c) const {
63 Square s = pieces.get_position(c, KING, 0);
64 return board.is_attacked_by(!c, s, pieces);
67 void make_move(Move m);
68 void undo_move(Move m);
69 bool is_legal(Move m);
70 bool is_dangerous(Move m);
72 // Search
73 unsigned long long int perft(unsigned int depth);
75 int quiescence(int alpha, int beta, int depth, const int ply);
77 template<NodeType node_type>
78 int search(int alpha, int beta, int depth, const int ply);
80 Move root(int max_depth);
82 // Killer Moves
83 void clear_killers();
84 Move get_killer_move(int depth, int index) {
85 return killer_moves[depth][index];
87 void set_killer_move(int depth, Move move);
88 bool is_killer_move(int depth, Move move) {
89 return (move == killer_moves[depth][0] ||
90 move == killer_moves[depth][1]);
93 // Position's evaluation
94 void init_eval();
95 int eval(int alpha, int beta);
96 int material_eval();
97 int position_eval();
99 // Output
100 void print_thinking_header();
101 void print_thinking(int depth, int score, Move m);
102 std::string output_pv(int depth, int score, Move m);
103 std::string output_move(Move m);
104 std::string output_square(Square s) {
105 return output_square(board.get_file(s), board.get_rank(s));
107 std::string output_square(File f, Rank r);
108 void print_tt_stats();
109 std::string debug_move(Move m);
112 #endif /* !GAME_H */