--- eval.c Thu Jun 19 10:28:44 2003+++ eval.new.c Wed Jun 18 23:04:02 2003@@ -1,4 +1,3 @@- /* * eval.c *@@ -2499,7 +2498,16 @@ cubeinfo *pci, evalcontext *pec, int nPlies, positionclass pc ) { int i, n0, n1;- int fUseReduction;++ int nCurrentPlies; /*When using reduction, this is nPlies -1 for the deeper reductiongroup, and nPlies-2 the rest of the time*/+ int nrg; /* Loop variable for reductiongroup */ + + int nNumberOfReductionGroups; /* The number of reduction groups to evaluate*/ + + int nLocalReductionGroup; + + + laRollList_t *rolls = NULL; laRollList_t *rollList = NULL; float arVariationOutput[ NUM_OUTPUTS ];@@ -2520,56 +2528,69 @@ if ( pec->nReduced && ( nPlies == pec->nPlies ) ) nReductionGroup = 0;-- fUseReduction = pec->nReduced && ( nPlies == 1 ) && ( pec->nPlies > 0 );-- if ( fUseReduction ) {- nReductionGroup = (nReductionGroup + 1) % pec->nReduced;- rollList = rollLists[ pec->nReduced ];- rolls = &rollList[ nReductionGroup ];+ + if (pec->nReduced && pec->nPlies == 1 && nPlies == 1) + /*Old style reduced evaluation*/ + { + rollList = rollLists[ pec->nReduced ]; + nLocalReductionGroup = nReductionGroup = (nReductionGroup + 1) % pec->nReduced; + nNumberOfReductionGroups = 1; + } else if (pec->nReduced && ( nPlies == 2 )) + /*Weighted average- style */ + { + rollList = rollLists[ pec->nReduced ]; + nLocalReductionGroup = nReductionGroup = (nReductionGroup + 1) % pec->nReduced; + nNumberOfReductionGroups = pec->nReduced; + } else { + /*No reduction*/ + rollList = allLists; + nLocalReductionGroup = 0; + nNumberOfReductionGroups = 1; }- else- rolls = &allLists[ 0 ];- + /* loop over rolls */ sumW = 0;- for ( r=0; r < rolls->numRolls; r++ ) {- n0 = rolls->d1[r];- n1 = rolls->d2[r];- w = rolls->wt[r];-- for( i = 0; i < 25; i++ ) {- anBoardNew[ 0 ][ i ] = anBoard[ 0 ][ i ];- anBoardNew[ 1 ][ i ] = anBoard[ 1 ][ i ];- }-- if( fAction )- fnAction();-- if( fInterrupt ) {- errno = EINTR;- return -1;+ for ( nrg = 0; nrg < nNumberOfReductionGroups; nrg++) { + rolls = &rollList[(nLocalReductionGroup + nrg) % nNumberOfReductionGroups]; + nCurrentPlies = nPlies - ((nrg == 0) ? 1 : 2); + for ( r=0; r < rolls->numRolls; r++ ) {+ n0 = rolls->d1[r];+ n1 = rolls->d2[r];+ w = rolls->wt[r];+ + for( i = 0; i < 25; i++ ) {+ anBoardNew[ 0 ][ i ] = anBoard[ 0 ][ i ];+ anBoardNew[ 1 ][ i ] = anBoard[ 1 ][ i ];+ }+ + if( fAction )+ fnAction();+ + if( fInterrupt ) {+ errno = EINTR;+ return -1;+ }+ + FindBestMovePlied( NULL, n0, n1, anBoardNew, pci, pec, 0,+ defaultFilters );+ + SwapSides( anBoardNew );+ + SetCubeInfo ( &ciOpp, pci->nCube, pci->fCubeOwner, !pci->fMove,+ pci->nMatchTo, pci->anScore, pci->fCrawford,+ pci->fJacoby, pci->fBeavers, pci->bgv );+ + /* Evaluate at lower ply */+ if( EvaluatePositionCache( anBoardNew, arVariationOutput,+ &ciOpp, pec, nCurrentPlies, + ClassifyPosition( anBoardNew, pci->bgv ) ) )+ return -1;+ + for( i = 0; i < NUM_OUTPUTS; i++ )+ arOutput[ i ] += w * arVariationOutput[ i ];+ sumW += w; }-- FindBestMovePlied( NULL, n0, n1, anBoardNew, pci, pec, 0,- defaultFilters );-- SwapSides( anBoardNew );-- SetCubeInfo ( &ciOpp, pci->nCube, pci->fCubeOwner, !pci->fMove,- pci->nMatchTo, pci->anScore, pci->fCrawford,- pci->fJacoby, pci->fBeavers, pci->bgv );-- /* Evaluate at 0-ply */- if( EvaluatePositionCache( anBoardNew, arVariationOutput,- &ciOpp, pec, nPlies - 1, - ClassifyPosition( anBoardNew, ciOpp.bgv ) ) )- return -1;-- for( i = 0; i < NUM_OUTPUTS; i++ )- arOutput[ i ] += w * arVariationOutput[ i ];- sumW += w; } /* reset reduction group */@@ -5896,14 +5917,20 @@ float arCfTemp[ 32 ]; cubeinfo aci[ 32 ]; #endif- int fUseReduction;+ laRollList_t *rolls = NULL; laRollList_t *rollList = NULL; int ir, w, sumW; int n0, n1;+ + int nLocalReductionGroup , nNumberOfReductionGroups; + + int nCurrentPlies; /*When using reduction, this is nPlies -1 for nLocalReductionGroup, and n-2 for the rest, */+ int nrg; /* Current reductiongroup */+ pc = ClassifyPosition ( anBoard, pciMove->bgv );- + if( pc > CLASS_OVER && nPlies > 0 && ! ( pc <= CLASS_PERFECT && !pciMove->nMatchTo ) ) { /* internal node; recurse */@@ -5926,68 +5953,83 @@ if ( pec->nReduced && ( nPlies == pec->nPlies ) ) nReductionGroup = 0;-- fUseReduction = pec->nReduced && ( nPlies == 1 ) && ( pec->nPlies > 0 );-- if ( fUseReduction ) {- nReductionGroup = (nReductionGroup + 1) % pec->nReduced;- rollList = rollLists[ pec->nReduced ];- rolls = &rollList[ nReductionGroup ];+ + if (pec->nReduced && pec->nPlies == 1 && nPlies == 1) + /*Old style reduced evaluation*/ + { + rollList = rollLists[ pec->nReduced ]; + nLocalReductionGroup = nReductionGroup = (nReductionGroup + 1) % pec->nReduced; + nNumberOfReductionGroups = 1; + } else if (pec->nReduced && ( nPlies == 2 )) + /*Weighted average- style */ + { + rollList = rollLists[ pec->nReduced ]; + nLocalReductionGroup = nReductionGroup = (nReductionGroup + 1) % pec->nReduced; + nNumberOfReductionGroups = pec->nReduced; + } else { + /*No reduction*/ + nLocalReductionGroup = 0; + rollList = allLists; + nNumberOfReductionGroups = 1; }- else- rolls = &allLists[ 0 ];- + /* loop over rolls */ sumW = 0;- for ( ir=0; ir < rolls->numRolls; ir++ ) {- n0 = rolls->d1[ir];- n1 = rolls->d2[ir];- w = rolls->wt[ir];-- for( i = 0; i < 25; i++ ) {- anBoardNew[ 0 ][ i ] = anBoard[ 0 ][ i ];- anBoardNew[ 1 ][ i ] = anBoard[ 1 ][ i ];- }-- if( fAction )- fnAction();-- if( fInterrupt ) {- errno = EINTR;- return -1;- }-- FindBestMovePlied( NULL, n0, n1, anBoardNew,- pciMove, pec, 0, defaultFilters );-- SwapSides( anBoardNew );-- SetCubeInfo ( &ciMoveOpp,- pciMove->nCube, pciMove->fCubeOwner,- ! pciMove->fMove, pciMove->nMatchTo,- pciMove->anScore, pciMove->fCrawford,- pciMove->fJacoby, pciMove->fBeavers, pciMove->bgv );-- /* Evaluate at 0-ply */- if( EvaluatePositionCubeful3( anBoardNew,- ar,- arCfTemp,- aci,- 2 * cci,- &ciMoveOpp,- pec, nPlies - 1, FALSE ) )- return -1;-- /* Sum up cubeless winning chances and cubeful equities */- - for( i = 0; i < NUM_OUTPUTS; i++ )- arOutput[ i ] += w * ar[ i ];- for ( i = 0; i < 2 * cci; i++ )- arCf[ i ] += w * arCfTemp[ i ];-- sumW += w;-+ + + for ( nrg = 0; nrg numRolls; ir++ ) {+ n0 = rolls->d1[ir];+ n1 = rolls->d2[ir];+ w = rolls->wt[ir];+ + for( i = 0; i < 25; i++ ) {+ anBoardNew[ 0 ][ i ] = anBoard[ 0 ][ i ];+ anBoardNew[ 1 ][ i ] = anBoard[ 1 ][ i ];+ }+ + if( fAction )+ fnAction();+ + if( fInterrupt ) {+ errno = EINTR;+ return -1;+ }+ + FindBestMovePlied( NULL, n0, n1, anBoardNew,+ pciMove, pec, 0, defaultFilters );+ + SwapSides( anBoardNew );+ + SetCubeInfo ( &ciMoveOpp,+ pciMove->nCube, pciMove->fCubeOwner,+ ! pciMove->fMove, pciMove->nMatchTo,+ pciMove->anScore, pciMove->fCrawford,+ pciMove->fJacoby, pciMove->fBeavers, pciMove->bgv );+ + /* Evaluate at lower ply */+ if( EvaluatePositionCubeful3( anBoardNew,+ ar,+ arCfTemp,+ aci,+ 2 * cci,+ &ciMoveOpp,+ pec, nCurrentPlies, FALSE ) )+ return -1;+ + /* Sum up cubeless winning chances and cubeful equities */+ + for( i = 0; i < NUM_OUTPUTS; i++ )+ arOutput[ i ] += w * ar[ i ];+ for ( i = 0; i < 2 * cci; i++ )+ arCf[ i ] += w * arCfTemp[ i ];+ + sumW += w;+ } } /* reset reduction group */