Commit 8a4015aa authored by Gaurav Kukreja's avatar Gaurav Kukreja

Removed unnecessary printf from pv-split-interactive

parent 683e2cd4
......@@ -26,67 +26,68 @@ extern int num_threads;
void ABIDStrategy::searchBestMove()
{
int alpha = -15000, beta = 15000;
int nalpha, nbeta, currentValue = 0;
_pv.clear(_maxDepth);
_currentBestMove.type = Move::none;
_currentMaxDepth=1;
/* iterative deepening loop */
do {
int alpha = -15000, beta = 15000;
int nalpha, nbeta, currentValue = 0;
_pv.clear(_maxDepth);
_currentBestMove.type = Move::none;
_currentMaxDepth=1;
/* iterative deepening loop */
do {
/* searches on same level with different alpha/beta windows */
while(1) {
nalpha = alpha, nbeta = beta;
_inPV = (_pv[0].type != Move::none);
if (_sc && _sc->verbose()) {
char tmp[100];
sprintf(tmp, "Alpha/Beta [%d;%d] with max depth %d", alpha, beta, _currentMaxDepth);
_sc->substart(tmp);
}
currentValue = pv_split(alpha, beta);
if (_sc && _sc->verbose())
printf("Subsearch finished with currentValue = %d\n", currentValue);
/* stop searching if a win position is found */
if (currentValue > 14900 || currentValue < -14900)
_stopSearch = true;
/* Don't break out if we haven't found a move */
if (_currentBestMove.type == Move::none)
_stopSearch = false;
if (_stopSearch) break;
/* if result is outside of current alpha/beta window,
* the search has to be rerun with widened alpha/beta
*/
if (currentValue <= nalpha) {
alpha = -15000;
if (beta<15000) beta = currentValue+1;
continue;
}
if (currentValue >= nbeta) {
if (alpha > -15000) alpha = currentValue-1;
beta=15000;
continue;
}
break;
}
/* searches on same level with different alpha/beta windows */
while(1) {
/* Window in both directions cause of deepening */
alpha = currentValue - 200, beta = currentValue + 200;
nalpha = alpha, nbeta = beta;
_inPV = (_pv[0].type != Move::none);
if (_stopSearch) break;
if (_sc && _sc->verbose()) {
char tmp[100];
sprintf(tmp, "Alpha/Beta [%d;%d] with max depth %d", alpha, beta, _currentMaxDepth);
_sc->substart(tmp);
}
currentValue = pv_split(alpha, beta);
printf("Subsearch finished with currentValue = %d\n", currentValue);
/* stop searching if a win position is found */
if (currentValue > 14900 || currentValue < -14900)
_stopSearch = true;
/* Don't break out if we haven't found a move */
if (_currentBestMove.type == Move::none)
_stopSearch = false;
if (_stopSearch) break;
/* if result is outside of current alpha/beta window,
* the search has to be rerun with widened alpha/beta
*/
if (currentValue <= nalpha) {
alpha = -15000;
if (beta<15000) beta = currentValue+1;
continue;
}
if (currentValue >= nbeta) {
if (alpha > -15000) alpha = currentValue-1;
beta=15000;
continue;
}
break;
_currentMaxDepth++;
}
/* Window in both directions cause of deepening */
alpha = currentValue - 200, beta = currentValue + 200;
if (_stopSearch) break;
while(_currentMaxDepth <= _maxDepth);
_currentMaxDepth++;
}
while(_currentMaxDepth <= _maxDepth);
_bestMove = _currentBestMove;
_bestMove = _currentBestMove;
}
int ABIDStrategy::pv_split(int alpha0, int beta0)
......@@ -94,7 +95,7 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
bool cutoff;
int depth;
int value;
int currentValue = -15000;
int currentValue = -15000;
int slave_id;
int num_slaves;
int pending_jobs;
......@@ -114,7 +115,7 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
alpha[0] = alpha0;
beta[0] = beta0;
_currentBestMove.type = Move::none;
_currentBestMove.type = Move::none;
// Play moves from the pv until you reach the lowest level
// If pv-moves are not possible use random moves
......@@ -123,13 +124,13 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
while (depth < (_currentMaxDepth-1))
{
list.clear();
_board->generateMoves(list);
_board->generateMoves(list);
m = _pv[depth];
// check if pv-move is possible
if ((m.type != Move::none) && (!list.isElement(m, 0, false)))
m.type = Move::none;
// get random move if pv-move is not possible
if (m.type == Move::none)
list.getNext(m, Move::none);
......@@ -147,7 +148,7 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
// Devide the work at each level
depth = _currentMaxDepth-1;
while (depth >= 0)
{
{
slave_id = 0;
list.clear();
_board->generateMoves(list);
......@@ -161,13 +162,12 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
slave_input.depth = depth+1;
slave_input.currentMaxDepth = _currentMaxDepth;
printf("Thread 0 testing %d moves at depth = %d\n",list.getLength(), depth);
while ( list.getNext(m, Move::none) )
{
slave_input.move = m;
MPI_Send(&slave_input, sizeof(Slave_Input), MPI_BYTE, slave_id+1, 10, MPI_COMM_WORLD);
MPI_Irecv(&slave_output[slave_id], sizeof(Slave_Output), MPI_BYTE, slave_id+1,
10, MPI_COMM_WORLD, &rcv_rq[slave_id]);
10, MPI_COMM_WORLD, &rcv_rq[slave_id]);
slave_id++;
......@@ -181,37 +181,37 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
while (pending_jobs > 0)
{
MPI_Waitany(num_slaves, rcv_rq, &slave_id, MPI_STATUS_IGNORE);
_sc->_leavesVisited += slave_output[slave_id].num_leaves;
_sc->_nodesVisited += slave_output[slave_id].num_nodes;
value = slave_output[slave_id].eval;
if (value > currentValue)
MPI_Waitany(num_slaves, rcv_rq, &slave_id, MPI_STATUS_IGNORE);
_sc->_leavesVisited += slave_output[slave_id].num_leaves;
_sc->_nodesVisited += slave_output[slave_id].num_nodes;
value = slave_output[slave_id].eval;
if (value > currentValue)
{
currentValue = value;
_pv = slave_output[slave_id].pv;
if (_sc)
_sc->foundBestMove(depth, _pv[depth], currentValue);
if (currentValue > alpha[depth])
{
currentValue = value;
_pv = slave_output[slave_id].pv;
if (_sc)
_sc->foundBestMove(depth, _pv[depth], currentValue);
if (currentValue > alpha[depth])
{
alpha[depth] = currentValue;
slave_input.beta = -alpha[depth];
}
/* alpha/beta cut off or win position ... */
if (currentValue>14900 || currentValue >= beta[depth])
cutoff = true;
alpha[depth] = currentValue;
slave_input.beta = -alpha[depth];
}
/* alpha/beta cut off or win position ... */
if (currentValue>14900 || currentValue >= beta[depth])
cutoff = true;
}
if ((list.getNext(m, Move::none)) && (cutoff == false))
{
slave_input.move = m;
if ((list.getNext(m, Move::none)) && (cutoff == false))
{
slave_input.move = m;
MPI_Send(&slave_input, sizeof(Slave_Input), MPI_BYTE, slave_id+1, 10, MPI_COMM_WORLD);
MPI_Irecv(&slave_output[slave_id], sizeof(Slave_Output), MPI_BYTE, slave_id+1,
MPI_Send(&slave_input, sizeof(Slave_Input), MPI_BYTE, slave_id+1, 10, MPI_COMM_WORLD);
MPI_Irecv(&slave_output[slave_id], sizeof(Slave_Output), MPI_BYTE, slave_id+1,
10, MPI_COMM_WORLD, &rcv_rq[slave_id]);
}
else
pending_jobs--;
}
else
pending_jobs--;
}
if (depth > 0)
......@@ -223,11 +223,11 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
alpha[depth-1] = currentValue;
}
if (depth == 0)
_currentBestMove = _pv[0];
_currentBestMove = _pv[0];
if (_sc)
_sc->finishedNode(depth, _pv.chain(depth));
depth--;
}
}
free(slave_output);
free(rcv_rq);
......@@ -247,88 +247,88 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
*/
int ABIDStrategy::alphabeta(int depth, int alpha, int beta)
{
int currentValue = -14999+depth, value;
Move m;
MoveList list;
bool depthPhase, doDepthSearch;
/* We make a depth search for the following move types... */
int maxType = (depth < _currentMaxDepth-1) ? Move::maxMoveType :
(depth < _currentMaxDepth) ? Move::maxPushType :
Move::maxOutType;
_board->generateMoves(list);
if (_sc && _sc->verbose()) {
char tmp[100];
sprintf(tmp, "Alpha/Beta [%d;%d], %d moves (%d depth)", alpha, beta,
list.count(Move::none), list.count(maxType));
_sc->startedNode(depth, tmp);
}
// don't use moves from the principal variation
m.type = Move::none;
// first, play all moves with depth search
depthPhase = true;
while (1) {
// get next move
if (m.type == Move::none) {
if (depthPhase)
depthPhase = list.getNext(m, maxType);
if (!depthPhase)
if (!list.getNext(m, Move::none)) break;
}
// we could start with a non-depth move from principal variation
doDepthSearch = depthPhase && (m.type <= maxType);
int currentValue = -14999+depth, value;
Move m;
MoveList list;
bool depthPhase, doDepthSearch;
_board->playMove(m);
/* We make a depth search for the following move types... */
int maxType = (depth < _currentMaxDepth-1) ? Move::maxMoveType :
(depth < _currentMaxDepth) ? Move::maxPushType :
Move::maxOutType;
/* check for a win position first */
if (!_board->isValid()) {
_board->generateMoves(list);
/* Shorter path to win position is better */
value = 14999-depth;
}
else {
if (doDepthSearch) {
/* opponent searches for its maximum; but we want the
* minimum: so change sign (for alpha/beta window too!)
*/
value = -alphabeta(depth+1, -beta, -alpha);
}
else {
value = evaluate();
}
if (_sc && _sc->verbose()) {
char tmp[100];
sprintf(tmp, "Alpha/Beta [%d;%d], %d moves (%d depth)", alpha, beta,
list.count(Move::none), list.count(maxType));
_sc->startedNode(depth, tmp);
}
_board->takeBack();
// don't use moves from the principal variation
m.type = Move::none;
// first, play all moves with depth search
depthPhase = true;
while (1) {
// get next move
if (m.type == Move::none) {
if (depthPhase)
depthPhase = list.getNext(m, maxType);
if (!depthPhase)
if (!list.getNext(m, Move::none)) break;
}
// we could start with a non-depth move from principal variation
doDepthSearch = depthPhase && (m.type <= maxType);
_board->playMove(m);
/* best move so far? */
if (value > currentValue) {
currentValue = value;
_pv.update(depth, m);
/* check for a win position first */
if (!_board->isValid()) {
/* alpha/beta cut off or win position ... */
if (currentValue>14900 || currentValue >= beta) {
if (_sc) _sc->finishedNode(depth, _pv.chain(depth));
return currentValue;
}
/* Shorter path to win position is better */
value = 14999-depth;
}
else {
if (doDepthSearch) {
/* opponent searches for its maximum; but we want the
* minimum: so change sign (for alpha/beta window too!)
*/
value = -alphabeta(depth+1, -beta, -alpha);
}
else {
value = evaluate();
}
}
/* maximize alpha */
if (currentValue > alpha) alpha = currentValue;
_board->takeBack();
/* best move so far? */
if (value > currentValue) {
currentValue = value;
_pv.update(depth, m);
/* alpha/beta cut off or win position ... */
if (currentValue>14900 || currentValue >= beta) {
if (_sc) _sc->finishedNode(depth, _pv.chain(depth));
return currentValue;
}
/* maximize alpha */
if (currentValue > alpha) alpha = currentValue;
}
if (_stopSearch) break; // depthPhase=false;
m.type = Move::none;
}
if (_stopSearch) break; // depthPhase=false;
m.type = Move::none;
}
if (_sc) _sc->finishedNode(depth, _pv.chain(depth));
if (_sc) _sc->finishedNode(depth, _pv.chain(depth));
return currentValue;
return currentValue;
}
// register ourselve
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment