Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 6 files changed
  • 0 comments
  • 1 contributor
1  src/game.cpp
@@ -98,7 +98,6 @@ void Game::new_position()
98 98 current_position().get_en_passant());
99 99
100 100 // Update the position for a new move
101   - current_position().inc_ply();
102 101 current_position().change_side();
103 102 zobrist.change_side(current_position().hash());
104 103 }
2  src/init.cpp
@@ -110,5 +110,5 @@ void Game::init(std::string fen)
110 110 iss >> fullmove;
111 111 int ply = 2 * (fullmove - 1);
112 112 if (current_position().get_turn_color() == BLACK) ++ply;
113   - current_position().set_ply(ply);
  113 + tree.set_ply(ply);
114 114 }
4 src/output.cpp
@@ -44,7 +44,7 @@ void Game::print_thinking(int depth, int score, Move m)
44 44 << std::setw(WIDE) << time.get_elapsed_time()
45 45 << std::setw(WIDE + 3) << nodes_count
46 46 << std::setw(WIDE - 3) << " ";
47   - int ply = current_position().get_ply();
  47 + const int ply = tree.get_ply();
48 48
49 49 if (current_position().get_turn_color() == BLACK) {
50 50 std::cout << " " << 1 + (ply / 2) << ". ...";
@@ -63,7 +63,7 @@ std::string Game::output_pv(int depth, int score, Move m)
63 63 {
64 64 std::ostringstream stream;
65 65 stream << " ";
66   - int ply = current_position().get_ply();
  66 + const int ply = tree.get_ply();
67 67 if (current_position().get_turn_color() == WHITE) {
68 68 stream << 1 + (ply / 2) << ". ";
69 69 }
14 src/position.h
@@ -28,7 +28,6 @@ class Position
28 28 private:
29 29 Hash zobrist_hash;
30 30 Hash material_zobrist_hash;
31   - uint16_t ply;
32 31 Piece capture;
33 32 std::bitset<4> castle_rights;
34 33 std::bitset<2> castle;
@@ -39,7 +38,6 @@ class Position
39 38
40 39 public:
41 40 Position() :
42   - ply(0),
43 41 en_passant(OUT),
44 42 halfmove_counter(0),
45 43 null_move_right(true),
@@ -58,18 +56,6 @@ class Position
58 56 void change_side() {
59 57 side_to_move = !side_to_move;
60 58 };
61   - uint16_t get_ply() const {
62   - return ply;
63   - };
64   - void set_ply(uint16_t i) {
65   - ply = i;
66   - };
67   - void inc_ply() {
68   - ++ply;
69   - };
70   - void dec_ply() {
71   - --ply;
72   - };
73 59 unsigned char get_halfmove() const {
74 60 return halfmove_counter;
75 61 };
15 src/search.cpp
@@ -29,15 +29,17 @@ inline bool Game::is_dangerous(Move m)
29 29 // current_position() is used assuming
30 30 // that the move as already been made.
31 31
32   - /*
33 32 if (board.get_piece(m.get_dest()).get_type() == PAWN) {
34 33 const Color c = !current_position().get_turn_color();
35 34 if (m.get_dest_rank() + RANK_6 * c == RANK_7) return true;
36 35 }
  36 +
  37 + /*
37 38 if (m.is_capture()) {
38 39 const Piece capture = current_position().get_capture();
39 40 if (capture.get_type() != PAWN) return true;
40 41 }
  42 +
41 43 return m.is_promotion();
42 44 */
43 45
@@ -251,15 +253,16 @@ int Game::search(int alpha, int beta, int depth, const int ply)
251 253 !is_in_check &&
252 254 !is_giving_check &&
253 255 !is_killer_move(depth, move) &&
254   - !is_dangerous(move);
  256 + !is_dangerous(move) &&
  257 + !move.is_castle() &&
  258 + legal_move_found &&
  259 + best_score < INF - MAX_PLY &&
  260 + pieces.count(!player) > 3;
255 261
256 262 if (fp_allowed && depth <= FUTILITY_DEPTH) {
257 263 // Using an array of margins is an idea from Crafty
258 264 score = material_eval() + FUTILITY_MARGINS[depth];
259 265 if (score < alpha) {
260   - if (score > best_score) {
261   - best_score = score;
262   - }
263 266 undo_move(move);
264 267 continue;
265 268 }
@@ -330,7 +333,7 @@ int Game::search(int alpha, int beta, int depth, const int ply)
330 333
331 334 Move Game::root(int max_depth)
332 335 {
333   - time.start_thinking(current_position().get_ply());
  336 + time.start_thinking(tree.get_ply());
334 337 Color player = current_position().get_turn_color();
335 338 print_thinking_header();
336 339 nodes_count = 0;
11 src/tree.h
@@ -25,9 +25,10 @@ class Tree
25 25 {
26 26 private:
27 27 Position tree[MAX_TREE];
28   - uint16_t tree_top; // TODO Redundant? current_position().get_ply()
  28 + uint16_t tree_offset;
  29 + uint16_t tree_top;
29 30 public:
30   - Tree() : tree_top(0) {}
  31 + Tree() : tree_offset(0), tree_top(0) {}
31 32 void push() {
32 33 tree[tree_top + 1] = tree[tree_top];
33 34 ++tree_top;
@@ -38,6 +39,12 @@ class Tree
38 39 Position& top() {
39 40 return tree[tree_top];
40 41 };
  42 + uint16_t get_ply() const {
  43 + return tree_offset + tree_top;
  44 + };
  45 + void set_ply(uint16_t ply) {
  46 + tree_offset = ply;
  47 + };
41 48 bool has_repetition_draw();
42 49 };
43 50

No commit comments for this range

Something went wrong with that request. Please try again.