Only in not performance critical code like pretty_pv(),
otherwise continue to use the good old C-style arrays
like in extract/insert PV where I have done some code
refactoring anyhow.
No functional change.
#include <cassert>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <sstream>
#include "movegen.h"
#include "notation.h"
#include "movegen.h"
#include "notation.h"
const int64_t K = 1000;
const int64_t M = 1000000;
const int64_t K = 1000;
const int64_t M = 1000000;
- StateInfo state[MAX_PLY_PLUS_2], *st = state;
+ std::stack<StateInfo> st;
Move* m = pv;
string san, padding;
size_t length;
Move* m = pv;
string san, padding;
size_t length;
s << san << ' ';
length += san.length() + 1;
s << san << ' ';
length += san.length() + 1;
- pos.do_move(*m++, *st++);
+ st.push(StateInfo());
+ pos.do_move(*m++, st.top());
StateInfo state[MAX_PLY_PLUS_2], *st = state;
TTEntry* tte;
StateInfo state[MAX_PLY_PLUS_2], *st = state;
TTEntry* tte;
- assert(m != MOVE_NONE && pos.is_pseudo_legal(m));
-
- pv.push_back(m);
- pos.do_move(m, *st++);
-
- while ( (tte = TT.probe(pos.key())) != NULL
- && (m = tte->move()) != MOVE_NONE // Local copy, TT entry could change
- && pos.is_pseudo_legal(m)
- && pos.pl_move_is_legal(m, pos.pinned_pieces())
- && ply < MAX_PLY
- && (!pos.is_draw<true, true>() || ply < 2))
- {
- pos.do_move(m, *st++);
- ply++;
- }
- pv.push_back(MOVE_NONE);
- do pos.undo_move(pv[--ply]); while (ply);
+ assert(pos.move_is_legal(pv[ply]));
+ pos.do_move(pv[ply++], *st++);
+ tte = TT.probe(pos.key());
+
+ } while ( tte
+ && pos.is_pseudo_legal(m = tte->move()) // Local copy, TT could change
+ && pos.pl_move_is_legal(m, pos.pinned_pieces())
+ && ply < MAX_PLY
+ && (!pos.is_draw<true, true>() || ply < 2));
+
+ pv.push_back(MOVE_NONE); // Must be zero-terminating
+
+ while (ply) pos.undo_move(pv[--ply]);
StateInfo state[MAX_PLY_PLUS_2], *st = state;
TTEntry* tte;
StateInfo state[MAX_PLY_PLUS_2], *st = state;
TTEntry* tte;
- Key k;
- Value v, m = VALUE_NONE;
-
- assert(pv[ply] != MOVE_NONE && pos.is_pseudo_legal(pv[ply]));
- k = pos.key();
- tte = TT.probe(k);
+ tte = TT.probe(pos.key());
- // Don't overwrite existing correct entries
- if (!tte || tte->move() != pv[ply])
+ if (!tte || tte->move() != pv[ply]) // Don't overwrite correct entries
- v = (pos.in_check() ? VALUE_NONE : evaluate(pos, m));
- TT.store(k, VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[ply], v, m);
+ if (pos.in_check())
+ v = m = VALUE_NONE;
+ else
+ v = evaluate(pos, m);
+
+ TT.store(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[ply], v, m);
- pos.do_move(pv[ply], *st++);
- } while (pv[++ply] != MOVE_NONE);
+ assert(pos.move_is_legal(pv[ply]));
+ pos.do_move(pv[ply++], *st++);
+
+ } while (pv[ply] != MOVE_NONE);
- do pos.undo_move(pv[--ply]); while (ply);
+ while (ply) pos.undo_move(pv[--ply]);