The informations in this class are used only for current ply and I could declare it inside the search function (allocated in stack).
But I found it's slower to declare it in the search function, why so much difference in speed between the two versions ?
Default position search to depth 20 :
version A : 3 470 138 N/s
version B : 2 736 985 N/s
Code: Select all
class ChessMoveOrder {
u32 phase;
u32 phaseNext;
u32 ply;
u32 position;
u32 pos_capture;
ChessMove moveHash;
ChessMove moveKiller1;
ChessMove moveKiller2;
u32 count;
ChessMoveSort movelist[MAX_PLAY_MOVES];
// ...
};
/////////////////////////
// * version A :
class ChessEngine {
// ...
ChessMoveOrder moveOrderList[MAX_DEPTH];
// ...
int search(int alpha, int beta, int depth, int ply);
// ...
};
int ChessEngine::search(int alpha, int beta, int depth, int ply)
{
// ...
moveOrderList[ply].init( ... );
while ((movePhase = movegen.getNextMove(moveOrderList[ply], move)) != ORDERMOVE_END) {
// ...
}
// ...
}
/////////////////////////
// * version B :
int ChessEngine::search(int alpha, int beta, int depth, int ply)
{
// ...
ChessMoveOrder moveOrder;
moveOrder.init( ... );
while ((movePhase = movegen.getNextMove(moveOrder, move)) != ORDERMOVE_END) {
// ...
}
// ...
}