Introducing Lazy Move Generation
[purplehaze.git] / src / game.h
blobb6f1afdff0fb69f7e31d86349d30e59e428c0d67
1 /* PurpleHaze 2.0.0
2 * Copyright (C) 2007-2011 Vincent Ollivier
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef GAME_H
19 #define GAME_H
21 #include <string>
23 #include "pieces.h"
24 #include "board.h"
25 #include "moves.h"
26 #include "node.h"
27 #include "tt.h"
28 #include "time.h"
29 #include "tree.h"
30 #include "zobrist.h"
32 enum NodeType : unsigned char {PV_NODE, CUT_NODE, ALL_NODE};
34 class Game
36 private:
37 Zobrist zobrist;
38 Move killer_moves[MAX_DEPTH][2];
40 public:
41 bool output_thinking;
42 unsigned int nodes_count; // Used in search
43 //list<Move> moves_history; // Temporary
44 Pieces pieces;
45 Board board;
46 Tree tree;
47 Time time;
48 Transpositions tt;
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_node();
57 void del_node();
58 Node& current_node() { return tree.top(); };
60 void init(string fen);
62 bool is_check(Color c) const {
63 return board.is_attacked_by(Color(!c),
64 pieces.get_position(c, KING, 0),
65 pieces);
69 //Moves movegen(bool captures_only = false);
70 void make_move(Move m);
71 void undo_move(Move m);
72 bool is_legal(Move m);
74 // Search
75 int perft(int depth);
76 int quiescence_search(int alpha, int beta, int depth);
77 //int alphabeta_search(int alpha, int beta, int depth);
78 int pv_search(int alpha, int beta, int depth, NodeType node_type);
79 Move root(int max_depth);
81 // Killer Moves
82 Move get_killer_move(int depth, int index) {
83 return killer_moves[depth][index];
85 void set_killer_move(int depth, Move move);
86 bool is_killer_move(int depth, Move move) {
87 return (move == killer_moves[depth][0] ||
88 move == killer_moves[depth][1]);
91 // Position's evaluation
92 int piece_eval(Color c, PieceType t, int i);
93 int eval();
95 // Output
96 void print_thinking_header();
97 void print_thinking(int depth, int score, Move m);
98 string output_principal_variation(int depth, Move m);
99 string output_move(Move m);
100 string output_square(Square s) {
101 return output_square(board.get_file(s), board.get_rank(s));
103 string output_square(File f, Rank r);
104 void print_tt_stats();
107 #endif /* !GAME_H */