Spectrum E(const Scene *scene, const Intersection &its, const Medium *medium, Sampler *sampler, int nSamples, bool handleIndirect) const { Spectrum EDir(0.0f), EIndir(0.0f); DirectSamplingRecord dRec(its); /* Sample the direct illumination component */ for (int i=0; i<nSamples; i++) { int maxIntermediateInteractions = -1; Spectrum directRadiance = scene->sampleAttenuatedEmitterDirect( dRec, its, medium, maxIntermediateInteractions, sampler->next2D()); if (!directRadiance.isZero()) { Float dp = dot(dRec.d, its.shFrame.n); if (dp > 0) EDir += directRadiance * dp; } } if (handleIndirect) { RadianceQueryRecord rRec(scene, sampler); rRec.newQuery(RadianceQueryRecord::ERadianceNoEmission, medium); rRec.its = its; if (!m_irrCache->get(rRec.its, EIndir)) handleMiss(RayDifferential(), rRec, EIndir); } return (EDir / (Float) nSamples) + EIndir; }
void CMoveGen::genMoves(CMoveList& moves, bool captures, bool quiets, bb_t from, bb_t to) const { EColor side = board().getSide(); bb_t occup = board().getOccupBits(); bb_t empty = board().getEmptyBits(); bb_t mask_to_pawn_c = board().getColorBits(toggleColor(side)) & to; bb_t mask_to_pawn_q = empty & to; bb_t mask_to_pieces = bbEmptyBoard; if (captures) mask_to_pieces |= board().getColorBits(toggleColor(side)); if (quiets) mask_to_pieces |= empty; mask_to_pieces &= to; bb_t x, y; bb_t pawns = board().getPieceBits(ePawn, side) & from; if (eWhite == side) { if (captures) { // caps NoWe x = shift_soea(shift_nowe(pawns & ~bbRank_7) & mask_to_pawn_c); while (x) moves.addDir(popFirstBit(x), eNowe); // caps NoEa x = shift_sowe(shift_noea(pawns & ~bbRank_7) & mask_to_pawn_c); while (x) moves.addDir(popFirstBit(x), eNoea); // prom NoWe x = shift_soea(shift_nowe(pawns & bbRank_7) & mask_to_pawn_c); while (x) addPromotions(moves, popFirstBit(x), eNowe); // prom NoEa x = shift_sowe(shift_noea(pawns & bbRank_7) & mask_to_pawn_c); while (x) addPromotions(moves, popFirstBit(x), eNoea); // prom North x = shift_sout(shift_nort(pawns & bbRank_7) & mask_to_pawn_q); while (x) addPromotions(moves, popFirstBit(x), eNort); // en-passant EField ep = board().getEp(); if (eNF != ep) { if (test_bit(shift_nowe(pawns), ep)) moves.add(EField(ep - eNowe), ep, eEnPassant); if (test_bit(shift_noea(pawns), ep)) moves.add(EField(ep - eNoea), ep, eEnPassant); } } if (quiets) { // single step x = shift_sout(shift_nort(pawns & ~bbRank_7) & mask_to_pawn_q); while (x) moves.addDir(popFirstBit(x), eNort); // double step x = shift_nort(shift_nort(pawns & bbRank_2) & empty) & mask_to_pawn_q; x = shift_sout(shift_sout(x)); while (x) moves.addDir(popFirstBit(x), EDir(eNort + eNort)); } } else { if (captures) { // caps SoWe x = shift_noea(shift_sowe(pawns & ~bbRank_2) & mask_to_pawn_c); while (x) moves.addDir(popFirstBit(x), eSowe); // caps SoEa x = shift_nowe(shift_soea(pawns & ~bbRank_2) & mask_to_pawn_c); while (x) moves.addDir(popFirstBit(x), eSoea); // prom SoWe x = shift_noea(shift_sowe(pawns & bbRank_2) & mask_to_pawn_c); while (x) addPromotions(moves, popFirstBit(x), eSowe); // prom SoEa x = shift_nowe(shift_soea(pawns & bbRank_2) & mask_to_pawn_c); while (x) addPromotions(moves, popFirstBit(x), eSoea); // prom South x = shift_nort(shift_sout(pawns & bbRank_2) & mask_to_pawn_q); while (x) addPromotions(moves, popFirstBit(x), eSout); EField ep = board().getEp(); if (eNF != ep) { if (test_bit(shift_sowe(pawns), ep)) moves.add(EField(ep - eSowe), ep, eEnPassant); if (test_bit(shift_soea(pawns), ep)) moves.add(EField(ep - eSoea), ep, eEnPassant); } } if (quiets) { // single step x = shift_nort(shift_sout(pawns & ~bbRank_2) & mask_to_pawn_q); while (x) moves.addDir(popFirstBit(x), eSout); // double step x = shift_sout(shift_sout(pawns & bbRank_7) & empty) & mask_to_pawn_q; x = shift_nort(shift_nort(x)); while (x) moves.addDir(popFirstBit(x), EDir(eSout + eSout)); } } x = board().getPieceBits(eKnight, side) & from; while (x) { EField from = popFirstBit(x); y = gl_bitboards.getAttacksN(from) & mask_to_pieces; while (y) moves.add(from, popFirstBit(y)); } x = board().getPieceBits(eBishop, side) & from; while (x) { EField from = popFirstBit(x); y = gl_bitboards.getAttacksB(from, occup) & mask_to_pieces; while (y) moves.add(from, popFirstBit(y)); } x = board().getPieceBits(eRook, side) & from; while (x) { EField from = popFirstBit(x); y = gl_bitboards.getAttacksR(from, occup) & mask_to_pieces; while (y) moves.add(from, popFirstBit(y)); } x = board().getPieceBits(eQueen, side) & from; while (x) { EField from = popFirstBit(x); y = gl_bitboards.getAttacksQ(from, occup) & mask_to_pieces; while (y) moves.add(from, popFirstBit(y)); } x = board().getPieceBits(eKing, side) & from; while (x) { EField from = popFirstBit(x); y = gl_bitboards.getAttacksK(from) & mask_to_pieces; while (y) moves.add(from, popFirstBit(y)); if (!board().isCheck() && quiets) { EField king_to = eNF; if (eWhite == side) { if (board().checkCastling(king_to, from, eCastleW_OO)) moves.add(from, king_to, eCastle, eCastleW_OO); if (board().checkCastling(king_to, from, eCastleW_OOO)) moves.add(from, king_to, eCastle, eCastleW_OOO); } if (eBlack == side) { if (board().checkCastling(king_to, from, eCastleB_OO)) moves.add(from, king_to, eCastle, eCastleB_OO); if (board().checkCastling(king_to, from, eCastleB_OOO)) moves.add(from, king_to, eCastle, eCastleB_OOO); } } } }