int main(int argc, char **argv) { readArgs: if(argIs("/D")) { MaxDepth = toValue(nextArg()); goto readArgs; } if(argIs("/W")) { Field_W = toValue(nextArg()); goto readArgs; } if(argIs("/H")) { Field_H = toValue(nextArg()); goto readArgs; } if(argIs("/F")) { SetField(nextArg()); goto readArgs; } errorCase(!m_isRange(MaxDepth, 0, IMAX)); errorCase(!m_isRange(Field_W, 1, FIELD_W_MAX)); errorCase(!m_isRange(Field_H, 1, FIELD_H_MAX)); readCmds: if(argIs("/C")) // curr eval { cout("%u\n", GetEval()); goto readCmds; } if(argIs("/N")) // next eval { uint evals[FIELD_W_MAX]; uint index; GetNextEvals(evals); for(index = 0; index < Field_W; index++) cout("%u\n", evals[index]); goto readCmds; } }
/* 現在の Depth, Field... の次の局面 (Depth + 1) を評価する。 */ static void GetNextEvals(uint *dest) // 次手の評価リスト -> dest { uint kind = Depth % 2 ? 2 : 1; // 現在の手番 uint x; Depth++; // 次の手番にする。 for(x = 0; x < Field_W; x++) { if(PutStone(x, kind)) { dest[x] = GetEval(); EraseStone(x); // 復帰 } else dest[x] = 0; } Depth--; // 復帰 }
extern "C" EVAL_API void GetEvalD(IEvaluateModel<double>** peval) { GetEval(peval); }
extern "C" EVAL_API void GetEvalF(IEvaluateModel<float>** peval) { GetEval(peval); }
// buscamos capturas y jaques y analizamos las posibilidades de escape. int CPartida::Quiesce(int alpha,int beta) { int value,a; if(cancelado + (stHistory >> 6)) // si llenamos el pozo lo dejamos en tablas { return GetEval(alpha,beta); } IncNodesQ(); u64 hash = Taux.GetHash(); int Valor_i; Valor_i = GetEval(alpha,beta); // Vamos con material de sobra if(Valor_i >= beta ) { return Valor_i; } value = a = alpha; if(Valor_i > alpha ) a = Valor_i; else a = alpha; SetHashHistory(hash); CJugada J; CSort Sort; Sort.Init(Taux,true); for(J = Sort.GetNextQ();J.ToInt();J = Sort.GetNextQ()) { if(cancelado) break; if(J.desglose.captura == rey) { a = ValorMate(1); PopHistory(); return a; } if(J.desglose.peso < (PesoCaptura) ) continue; Move(J); if(!Taux.EsAtacada(Taux.PosReyes[Taux.ColorJuegan^1],Taux.ColorJuegan^1) ) { value = -Quiesce(-beta, -a); } TakeBack(); if(value > a) { a = value; if(a >= beta ) { break; } } } // for PopHistory(); return ( a ); }
PTErr_t PTEvaluate ( PTRefNum_t PTRefNum, PTEvalDTPB_p evalDef, PTEvalTypes_t evalID, KpInt32_t devNum, KpInt32_t aSync, opRefNum_p opRefNum, callBack_p callBack) { PTErr_t PTErr; PTEvalDTPB_t lEvalDef; PTCompDef_t thisInput [FUT_NICHAN], thisOutput [FUT_NOCHAN]; PTRefNum_t PTList [MAX_PT_CHAIN_SIZE]; PTTable_p evalList [MAX_PT_CHAIN_SIZE], PTTableP; PTTable_p* listStart; KpInt32_t theSerialCount, i1, i2, i3, i4, nOutputs, nFuts, PTcount; KpUInt32_t tempMemNeeded, oMask, ioMaskList [MAX_PT_CHAIN_SIZE]; PTImgAddr_t addr; #if defined (KCP_ACCEL) PTEvalTypes_t evaluator; KpInt32_t numEvals; #endif if (devNum) {} if (aSync) {} if (opRefNum) {} #if defined (KCP_MACPPC_MP) KCPInitializeMP (); #endif PTErr = getPTStatus (PTRefNum); /* must be an active or serial PT */ if ((PTErr != KCP_PT_ACTIVE) && (PTErr != KCP_SERIAL_PT)) { goto ErrOut0; } #if defined (KCP_ACCEL) PTErr = GetEval (evalID, &evaluator); /* get an evaluator */ if (PTErr != KCP_SUCCESS) { goto ErrOut0; } #endif /* valid PTEvalDTPB_p? */ if (evalDef == NULL) goto ErrOut1; if (evalDef->input == NULL) goto ErrOut1; if (evalDef->output == NULL) goto ErrOut1; if (evalDef->nInputs > FUT_NICHAN) goto ErrOut3; if (evalDef->nOutputs > FUT_NOCHAN) goto ErrOut3; /* set up the local evaluation structures */ /* set input and output to NULL */ /* this preserves the channel position while allowing */ /* the number of channels to indicate the number of valid addresses */ /* this is needed to keep both the CTE and SW evaluations happy */ for (i1 = 0; i1 < FUT_NICHAN; i1++) { thisInput[i1].pelStride = 0; thisInput[i1].lineStride = 0; thisInput[i1].addr = NULL; } lEvalDef.nPels = evalDef->nPels; lEvalDef.nLines = evalDef->nLines; lEvalDef.nInputs = FUT_NICHAN; lEvalDef.dataTypeI = evalDef->dataTypeI; lEvalDef.input = thisInput; for (i1 = 0; i1 < evalDef->nInputs; i1++) { lEvalDef.input[i1].pelStride = evalDef->input[i1].pelStride; lEvalDef.input[i1].lineStride = evalDef->input[i1].lineStride; lEvalDef.input[i1].addr = evalDef->input[i1].addr; } /* output addresses are loaded in the evaluation loop, no need to do anything here */ /* clear the PT and evaluation lists, just for clarity */ for (i1 = 0; i1 < MAX_PT_CHAIN_SIZE; i1++) { PTList[i1] = NULL; evalList[i1] = NULL; } /* get the list of PTs which we must actually evaluate */ PTErr = resolvePTData (PTRefNum, &theSerialCount, PTList); /* set up list of futs through which the image is evaluated */ for (i1 = 0; i1 < theSerialCount; i1++) { PTTableP = lockPTTable (PTList[i1]); /* lock tables while evaluating */ evalList[i1] = PTTableP; } /* initialize the evaluation list */ PTErr = setupEvalList (theSerialCount, evalList, ioMaskList, evalDef, &tempMemNeeded); if (PTErr != KCP_SUCCESS) { goto ErrOut2; } /* if temporary memory is not needed, */ /* then evaluate a full image at a time until */ /* the image has been processed through all futs */ /* if temporary memory is needed, */ /* then this level processes the image just once */ /* and a lower level processes the image through all futs */ if (tempMemNeeded == 0) { PTcount = theSerialCount; } else { PTcount = 1; } initProgressPasses (PTcount, callBack); /* process the image through each fut in the list */ for (i1 = 0; i1 < PTcount; i1++) { /* set up the output data addresses */ /* use io mask to order output channels properly */ if (tempMemNeeded == 1) { nFuts = theSerialCount; /* this many futs to evaluate */ listStart = &evalList[0]; oMask = FUT_OMASK(ioMaskList[nFuts-1]); /* use mask of last fut */ } else { nFuts = 1; /* evaluate one fut */ listStart = &evalList[i1]; oMask = FUT_OMASK(ioMaskList[i1]); /* use mask of this fut */ } /* initialize the output data structures */ lEvalDef.nOutputs = FUT_NOCHAN; lEvalDef.dataTypeO = evalDef->dataTypeO; lEvalDef.output = thisOutput; for (i2 = 0; i2 < FUT_NOCHAN; i2++) { thisOutput[i2].pelStride = 0; thisOutput[i2].lineStride = 0; thisOutput[i2].addr = NULL; } /* set the output channel addresses */ if (i1 == (PTcount -1)) { /* last, just use supplied stuff */ for (i2 = 0, nOutputs = 0; i2 < evalDef->nOutputs; i2++) { lEvalDef.output[i2].pelStride = evalDef->output[i2].pelStride; lEvalDef.output[i2].lineStride = evalDef->output[i2].lineStride; lEvalDef.output[i2].addr = evalDef->output[i2].addr; nOutputs++; /* count actual outputs */ } getDataBytes (evalDef->dataTypeO, &i3); /* get output data size */ if (i3 == 0) { nOutputs = 3; } } else { for (i2 = oMask, i3 = 0, i4 = 0, nOutputs = 0; i2 != 0; i2 >>= 1, i3++) { if ((i2 & 1) == 1) { /* this output channel is needed */ while ((addr = evalDef->output[i4].addr) == NULL) { i4++; /* get next available output channel */ } if (i4 > evalDef->nOutputs) { PTErr = KCP_PTERR_4; /* programming error */ goto ErrOut2; } lEvalDef.output[i3].pelStride = evalDef->output[i4].pelStride; lEvalDef.output[i3].lineStride = evalDef->output[i4].lineStride; lEvalDef.output[i3].addr = addr; i4++; /* next output address */ nOutputs++; /* count actual outputs */ } } } #if defined (KCP_ACCEL) /* if there are less than FASTER_IN_SW evaluations, it's faster to do it in software. */ numEvals = lEvalDef.nPels * lEvalDef.nLines * nOutputs; if ((numEvals < FASTER_IN_SW) || (tempMemNeeded == 1)) { evaluator = KCP_EVAL_SW; } switch (evaluator) { case KCP_EVAL_SW: /* evaluate in software */ software_evaluation: #endif PTErr = PTEvalSeq (nFuts, listStart, ioMaskList, &lEvalDef, callBack); if (PTErr != KCP_SUCCESS) { goto ErrOut2; } #if defined (KCP_ACCEL) break; case KCP_EVAL_CTE: /* evaluate using the NFE */ { PTRefNum_t thePTRefNum; KpHandle_t PTData; thePTRefNum = listStart[0]->refNum; /* get the PT reference number */ PTData = getPTData (thePTRefNum); /* get the transform data */ PTErr = PT_eval_cteDT (PTData, &lEvalDef, 0, 0, callBack); if ((PTErr == KCP_CTE_GRID_TOO_BIG) || (PTErr == KCP_CTE_NOT_ATTEMPTED)) { goto software_evaluation; } break; } default: PTErr = KCP_INVAL_EVAL; break; } #else if (evalID) {} /* unreferenced formal parameter */ #endif /* output for this PT is input for next PT */ lEvalDef.nInputs = lEvalDef.nOutputs; lEvalDef.dataTypeI = lEvalDef.dataTypeO; for (i2 = 0; i2 < lEvalDef.nInputs; i2++) { lEvalDef.input[i2].pelStride = lEvalDef.output[i2].pelStride; lEvalDef.input[i2].lineStride = lEvalDef.output[i2].lineStride; lEvalDef.input[i2].addr = lEvalDef.output[i2].addr; } } ErrOut2: /* unlock the PTs used for evaluation */ for (i1 = 0; i1 < theSerialCount; i1++) { unlockPTTable (PTList[i1]); } ErrOut0: return (PTErr); ErrOut1: PTErr = KCP_BAD_PTR; goto ErrOut0; ErrOut3: PTErr = KCP_INVAL_EVAL; goto ErrOut0; }