Use std::stack instead of fixed size array

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.
This commit is contained in:
Marco Costalba
2012-10-26 18:01:13 +02:00
parent 00a853950f
commit cd80762c13
2 changed files with 33 additions and 33 deletions

View File

@@ -20,7 +20,7 @@
#include <cassert> #include <cassert>
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include <string> #include <stack>
#include "movegen.h" #include "movegen.h"
#include "notation.h" #include "notation.h"
@@ -226,7 +226,7 @@ string pretty_pv(Position& pos, int depth, Value value, int64_t msecs, Move pv[]
const int64_t K = 1000; const int64_t K = 1000;
const int64_t M = 1000000; const int64_t M = 1000000;
StateInfo state[MAX_PLY_PLUS_2], *st = state; std::stack<StateInfo> st;
Move* m = pv; Move* m = pv;
string san, padding; string san, padding;
size_t length; size_t length;
@@ -261,7 +261,8 @@ string pretty_pv(Position& pos, int depth, Value value, int64_t msecs, Move pv[]
s << san << ' '; s << san << ' ';
length += san.length() + 1; length += san.length() + 1;
pos.do_move(*m++, *st++); st.push(StateInfo());
pos.do_move(*m++, st.top());
} }
while (m != pv) while (m != pv)

View File

@@ -1547,29 +1547,27 @@ void RootMove::extract_pv_from_tt(Position& pos) {
StateInfo state[MAX_PLY_PLUS_2], *st = state; StateInfo state[MAX_PLY_PLUS_2], *st = state;
TTEntry* tte; TTEntry* tte;
int ply = 1; int ply = 0;
Move m = pv[0]; Move m = pv[0];
assert(m != MOVE_NONE && pos.is_pseudo_legal(m));
pv.clear(); pv.clear();
pv.push_back(m);
pos.do_move(m, *st++);
while ( (tte = TT.probe(pos.key())) != NULL do {
&& (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))
{
pv.push_back(m); pv.push_back(m);
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]);
} }
@@ -1581,27 +1579,28 @@ void RootMove::insert_pv_in_tt(Position& pos) {
StateInfo state[MAX_PLY_PLUS_2], *st = state; StateInfo state[MAX_PLY_PLUS_2], *st = state;
TTEntry* tte; TTEntry* tte;
Key k;
Value v, m = VALUE_NONE;
int ply = 0; int ply = 0;
Value v, m;
assert(pv[ply] != MOVE_NONE && pos.is_pseudo_legal(pv[ply]));
do { do {
k = pos.key(); tte = TT.probe(pos.key());
tte = TT.probe(k);
// Don't overwrite existing correct entries if (!tte || tte->move() != pv[ply]) // Don't overwrite correct entries
if (!tte || tte->move() != pv[ply])
{ {
v = (pos.in_check() ? VALUE_NONE : evaluate(pos, m)); if (pos.in_check())
TT.store(k, VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[ply], v, m); 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++);
do pos.undo_move(pv[--ply]); while (ply); } while (pv[ply] != MOVE_NONE);
while (ply) pos.undo_move(pv[--ply]);
} }