Update copyright
[purplehaze.git] / src / game.h
blob65af760b499694a54e5d5a678b0091affa647fb8
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 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;
51 Game(const int tt_size = TT_SIZE, const int mt_size = MT_SIZE) :
52 material_table(mt_size),
53 output_thinking(false),
54 nodes_count(0),
55 tt(tt_size)
57 init_eval(); // PST
58 Moves::init_mvv_lva_scores();
61 void add_piece(Color c, PieceType t, Square s);
62 void del_piece(Color c, PieceType t, int i);
63 void del_piece(Piece p) {
64 del_piece(p.color(), p.type(), p.index());
67 void new_position();
68 void del_position();
69 Position& current_position() {
70 return tree.top();
73 void init(std::string fen);
75 bool is_check(Color c) const {
76 Square s = pieces.position(c, KING, 0);
77 return board.is_attacked_by(!c, s, pieces);
80 void make_move(Move m);
81 void undo_move(Move m);
82 bool is_legal(Move m);
83 bool is_dangerous(Move m);
85 // Search
86 unsigned long long int perft(unsigned int depth);
88 int quiescence(int alpha, int beta, int depth, const int ply);
90 template<NodeType node_type>
91 int search(int alpha, int beta, int depth, const int ply);
93 Move root(int max_depth);
95 // Killer Moves
96 void clear_killers();
98 Move killer(int depth, int index) {
99 return killer_moves[depth][index];
102 Move (&killers(const int depth))[MAX_KILLERS] {
103 return killer_moves[depth];
105 void set_killer(const Move move, const int depth);
106 bool is_killer(const Move move, const int depth) {
107 return (move == killer_moves[depth][0] ||
108 move == killer_moves[depth][1]);
111 // Position's evaluation
112 void init_eval();
113 int eval(int alpha, int beta);
114 int material_eval();
115 int position_eval();
117 // Output
118 void print_thinking_header();
119 void print_thinking(int depth, int score, Move m);
120 std::string output_pv(int depth, int score, Move m);
121 std::string output_move(Move m);
122 std::string output_square(Square s) {
123 return output_square(board.file(s), board.rank(s));
125 std::string output_square(File f, Rank r);
126 void print_tt_stats();
127 std::string debug_move(Move m);
130 #endif /* !GAME_H */