int Evaluation::evaluateCenter(int color, Position& position) { assert(Color::isValid(color)); int pawnCenter = 0; for (auto squares = position.pieces[color][PieceType::PAWN].squares; squares != 0; squares = Bitboard::remainder(squares)) { int square = Bitboard::next(squares); pawnCenter += evaluateCenter(color, position, square, Square::pawnDirections[color]); } int knightCenter = 0; for (auto squares = position.pieces[color][PieceType::KNIGHT].squares; squares != 0; squares = Bitboard::remainder(squares)) { int square = Bitboard::next(squares); knightCenter += evaluateCenter(color, position, square, Square::knightDirections); } int bishopCenter = 0; for (auto squares = position.pieces[color][PieceType::BISHOP].squares; squares != 0; squares = Bitboard::remainder(squares)) { int square = Bitboard::next(squares); bishopCenter += evaluateCenter(color, position, square, Square::bishopDirections); } int queenCenter = 0; for (auto squares = position.pieces[color][PieceType::QUEEN].squares; squares != 0; squares = Bitboard::remainder(squares)) { int square = Bitboard::next(squares); queenCenter += evaluateCenter(color, position, square, Square::queenDirections); } return pawnCenter * 3 + knightCenter * 4 + bishopCenter * 2 + queenCenter; }
IRResultType CohesiveSurface3d :: initializeFrom(InputRecord *ir) { IRResultType result; // first call parent StructuralElement :: initializeFrom(ir); // read the area from the input file IR_GIVE_FIELD(ir, area, _IFT_CohSur3d_area); if ( area < 0. ) { OOFEM_ERROR("negative area specified"); } // read shift constants of second (periodic) particle form the input file (if defined) ///@todo Why not a vector input instead? IR_GIVE_OPTIONAL_FIELD(ir, kx, _IFT_CohSur3d_kx); IR_GIVE_OPTIONAL_FIELD(ir, ky, _IFT_CohSur3d_ky); IR_GIVE_OPTIONAL_FIELD(ir, kz, _IFT_CohSur3d_kz); // evaluate number of Dof Managers numberOfDofMans = dofManArray.giveSize(); if ( numberOfDofMans <= 0 ) { OOFEM_ERROR("unread nodes: Element %d", this->giveNumber() ); } if ( ( numberOfDofMans == 3 ) & ( kx == 0 ) & ( ky == 0 ) & ( kz == 0 ) ) { OOFEM_ERROR("no periodic shift defined: Element %d", this->giveNumber() ); } // shifts of periodic particles if ( numberOfDofMans == 3 ) { Node *nodeC; nodeC = this->giveNode(3); kxa = this->kx * nodeC->giveCoordinate(1); kyb = this->ky * nodeC->giveCoordinate(2); kzc = this->kz * nodeC->giveCoordinate(3); } // evaluate the length giveLength(); if ( length <= 0. ) { OOFEM_ERROR("negative length evaluated: Element %d", this->giveNumber() ) // evaluate the coordinates of the center evaluateCenter(); } // evaluate the local coordinate system evaluateLocalCoordinateSystem(); return IRRT_OK; }
int Evaluation::evaluate(Position& position, bool heavy, int beta, bool dumpoutput) { // Initialize int myColor = position.activeColor; int oppositeColor = Color::opposite(myColor); int value = 0; // Evaluate material int mymaterial = evaluateMaterial(myColor, position); int materialScore = (mymaterial - evaluateMaterial(oppositeColor, position)) * materialWeight / MAX_WEIGHT; value += materialScore; if (dumpoutput) { std::cout << " materialscore: " << mymaterial * materialWeight / MAX_WEIGHT << " " << materialScore; } if (value >= beta + BETA_THRESHOLD) { return value; } if (heavy) { double materialRatio =(double) mymaterial / maxMaterial; // Evaluate mobility int mymobility = evaluateMobility(myColor, position); int mobilityScore = (mymobility - evaluateMobility(oppositeColor, position)) * mobilityWeight / MAX_WEIGHT; value += mobilityScore; if (dumpoutput) { std::cout << " mobilityscore: " << mymobility * mobilityWeight / MAX_WEIGHT << " " << mobilityScore; } // Evaluate center control int mycentre = evaluateCenter(myColor, position); int centerScore = (mycentre - evaluateCenter(oppositeColor, position)) * materialRatio * centerWeight / MAX_WEIGHT; value += centerScore; if (dumpoutput) { std::cout << " centrescore: " << int (mycentre * materialRatio * centerWeight / MAX_WEIGHT) << " " << centerScore; } // Evaluate Pawn structure int mypawn = evaluatePawn(myColor, position); int pawnScore = (mypawn - evaluatePawn(oppositeColor, position)) * pawnStructureWeight / MAX_WEIGHT; value += pawnScore; if (dumpoutput) { std::cout << " pawnscore: " << int(mypawn * pawnStructureWeight / MAX_WEIGHT) << " " << pawnScore; } // Evaluate King Safety int myking = evaluateKingSafety(myColor, position); int kingSafetyScore = (myking - evaluateKingSafety(oppositeColor, position)) * materialRatio * kingSafetyWeight / MAX_WEIGHT; value += kingSafetyScore; if (dumpoutput) { std::cout << " kingscore: " << int(myking * materialRatio * kingSafetyWeight / MAX_WEIGHT) << " " << kingSafetyScore; } } // Add Tempo value += TEMPO; assert(std::abs(value) < Value::CHECKMATE_THRESHOLD); return value; }