Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronize main project (Closing Milestone v14.0.2) #17

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
matrix:
wasm_simd: ['yes', 'no']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -104,16 +104,7 @@ jobs:
docker-compose run -e uci_exe="node public/uci.js" -e sign_ref=${{ env.sign_ref }} -e UCI_NNUE_FILE="../${{ env.default_net }}" node
bash tests/bench-signature.sh

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: no-embedded-nnue
path: src/emscripten/public/stockfish*

- name: Publish to NPM
if: startsWith(github.ref, 'refs/tags/')
working-directory: src/emscripten/public
run: |
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
npm publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
14 changes: 8 additions & 6 deletions src/bitboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,28 +463,30 @@ inline Bitboard attacks_bb(Square s, Bitboard occupied) {

/// pop_rider() finds and clears a rider in a (hybrid) rider type

inline RiderType pop_rider(RiderType* r) {
assert(*r);
const RiderType r2 = *r & ~(*r - 1);
*r &= *r - 1;
inline RiderType pop_rider(RiderType& r) {
assert(r);
const RiderType r2 = r & ~(r - 1);
r &= r - 1;
return r2;
}

inline Bitboard attacks_bb(Color c, PieceType pt, Square s, Bitboard occupied) {
assert(pt != NO_PIECE_TYPE);
Bitboard b = LeaperAttacks[c][pt][s];
RiderType r = AttackRiderTypes[pt];
while (r)
b |= rider_attacks_bb(pop_rider(&r), s, occupied);
b |= rider_attacks_bb(pop_rider(r), s, occupied);
return b & PseudoAttacks[c][pt][s];
}


template <bool Initial=false>
inline Bitboard moves_bb(Color c, PieceType pt, Square s, Bitboard occupied) {
assert(pt != NO_PIECE_TYPE);
Bitboard b = LeaperMoves[Initial][c][pt][s];
RiderType r = MoveRiderTypes[Initial][pt];
while (r)
b |= rider_attacks_bb(pop_rider(&r), s, occupied);
b |= rider_attacks_bb(pop_rider(r), s, occupied);
return b & PseudoMoves[Initial][c][pt][s];
}

Expand Down
6 changes: 4 additions & 2 deletions src/endgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ Value Endgame<KPK>::operator()(const Position& pos) const {
Color us = strongSide == pos.side_to_move() ? WHITE : BLACK;

// Non-standard promotion, evaluation unclear
if ( pos.promotion_zone(us) != rank_bb(relative_rank(us, RANK_8, pos.max_rank()))
/// yjf2002ghty: Since KPK means King-Pawn vs. King Endgame, I assume the piece type is PAWN. It can cause problems if the pawn is something else (e.g. Custom pawn piece)
if ( pos.promotion_zone(us, PAWN) != rank_bb(relative_rank(us, RANK_8, pos.max_rank()))
|| RANK_MAX != RANK_8
|| !(pos.promotion_piece_types(us) & QUEEN))
{
Expand Down Expand Up @@ -937,7 +938,8 @@ ScaleFactor Endgame<KPKP>::operator()(const Position& pos) const {

// Probe the KPK bitbase with the weakest side's pawn removed. If it's a draw,
// it's probably at least a draw even with the pawn.
if ( pos.promotion_zone(us) != rank_bb(relative_rank(us, RANK_8, pos.max_rank()))
/// yjf2002ghty: Since KPKP means King-Pawn vs. King-Pawn Endgame, I assume the piece type is PAWN. It can cause problems if the pawn is something else (e.g. Custom pawn piece)
if ( pos.promotion_zone(us, PAWN) != rank_bb(relative_rank(us, RANK_8, pos.max_rank()))
|| RANK_MAX != RANK_8
|| !(pos.promotion_piece_types(us) & QUEEN))
return SCALE_FACTOR_NONE;
Expand Down
7 changes: 4 additions & 3 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ namespace {
// Piece promotion bonus
if (pos.promoted_piece_type(Pt) != NO_PIECE_TYPE)
{
Bitboard zone = pos.promotion_zone(Us);
Bitboard zone = pos.promotion_zone(Us, Pt);
if (zone & (b | s))
score += make_score(PieceValue[MG][pos.promoted_piece_type(Pt)] - PieceValue[MG][Pt],
PieceValue[EG][pos.promoted_piece_type(Pt)] - PieceValue[EG][Pt]) / (zone & s && b ? 6 : 12);
Expand Down Expand Up @@ -750,7 +750,7 @@ namespace {
if (pos.promoted_piece_type(pt))
{
otherChecks = attacks_bb(Us, pos.promoted_piece_type(pt), ksq, pos.pieces()) & attackedBy[Them][pt]
& pos.promotion_zone(Them) & pos.board_bb();
& pos.promotion_zone(Them, pt) & pos.board_bb();
if (otherChecks & safe)
kingDanger += SafeCheck[FAIRY_PIECES][more_than_one(otherChecks & safe)];
else
Expand Down Expand Up @@ -1147,7 +1147,8 @@ namespace {
bool pawnsOnly = !(pos.pieces(Us) ^ pos.pieces(Us, PAWN));

// Early exit if, for example, both queens or 6 minor pieces have been exchanged
if (pos.non_pawn_material() < SpaceThreshold && !pawnsOnly && pos.double_step_region(Us))
/// yjf2002ghty: By default double step is used for pawns in enhancing opening evaluation, so I assume the piece type is PAWN. It can cause problems if the pawn is something else (e.g. Custom pawn piece)
if (pos.non_pawn_material() < SpaceThreshold && !pawnsOnly && pos.double_step_region(Us, PAWN))
return SCORE_ZERO;

constexpr Color Them = ~Us;
Expand Down
2 changes: 1 addition & 1 deletion src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,4 @@ void init(int argc, char* argv[]) {

} // namespace CommandLine

} // namespace Stockfish
} // namespace Stockfish
12 changes: 8 additions & 4 deletions src/movegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ namespace {
constexpr Direction UpRight = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
constexpr Direction UpLeft = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);

const Bitboard promotionZone = pos.promotion_zone(Us);
/// yjf2002ghty: Since it's generate_pawn_moves, I assume the piece type is PAWN. It can cause problems if the pawn is something else (e.g. Custom pawn piece)
const Bitboard promotionZone = pos.promotion_zone(Us, PAWN);
const Bitboard standardPromotionZone = pos.sittuyin_promotion() ? Bitboard(0) : promotionZone;
const Bitboard doubleStepRegion = pos.double_step_region(Us);
const Bitboard tripleStepRegion = pos.triple_step_region(Us);
/// yjf2002ghty: Since it's generate_pawn_moves, I assume the piece type is PAWN. It can cause problems if the pawn is something else (e.g. Custom pawn piece)
const Bitboard doubleStepRegion = pos.double_step_region(Us, PAWN);
/// yjf2002ghty: Since it's generate_pawn_moves, I assume the piece type is PAWN. It can cause problems if the pawn is something else (e.g. Custom pawn piece)
const Bitboard tripleStepRegion = pos.triple_step_region(Us, PAWN);

const Bitboard pawns = pos.pieces(Us, PAWN);
const Bitboard movable = pos.board_bb(Us, PAWN) & ~pos.pieces();
Expand Down Expand Up @@ -302,13 +305,14 @@ namespace {
Bitboard b = ( (attacks & pos.pieces())
| (quiets & ~pos.pieces()));
Bitboard b1 = b & target;
Bitboard promotion_zone = pos.promotion_zone(Us);
Bitboard promotion_zone = pos.promotion_zone(Us, Pt);
PieceType promPt = pos.promoted_piece_type(Pt);
Bitboard b2 = promPt && (!pos.promotion_limit(promPt) || pos.promotion_limit(promPt) > pos.count(Us, promPt)) ? b1 : Bitboard(0);
Bitboard b3 = pos.piece_demotion() && pos.is_promoted(from) ? b1 : Bitboard(0);
Bitboard pawnPromotions = pos.variant()->promotionPawnTypes[Us] & Pt ? b & (Type == EVASIONS ? target : ~pos.pieces(Us)) & promotion_zone : Bitboard(0);
Bitboard epSquares = pos.variant()->enPassantTypes[Us] & Pt ? attacks & ~quiets & pos.ep_squares() & ~pos.pieces() : Bitboard(0);


// target squares considering pawn promotions
if (pawnPromotions && pos.mandatory_pawn_promotion())
b1 &= ~pawnPromotions;
Expand Down
42 changes: 40 additions & 2 deletions src/movegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ namespace Stockfish {
class Position;

enum GenType {
/// yjf2002ghty: I think it's better to add some explanations here so that new developers can understand what these means, as some of the terms connot be found in chessprogramming wiki. I'm not sure if my explanations are correct. If there are anything wrong, please point it out.

//Moves that a piece is removed from the board as part of the completion of the move
CAPTURES,
//Moves which do not alter material, thus no captures nor promotions
QUIETS,
//Moves which do not alter material, and give check to opponent
QUIET_CHECKS,
//Check evasion moves, including interpositions, attacker capture and king withdrawal
EVASIONS,
//Moves that are not check evasion moves
NON_EVASIONS,
//Moves that are legal
LEGAL
};

Expand All @@ -55,12 +63,37 @@ inline bool operator<(const ExtMove& f, const ExtMove& s) {
template<GenType>
ExtMove* generate(const Position& pos, ExtMove* moveList);

constexpr size_t moveListSize = sizeof(ExtMove) * MAX_MOVES;

/// The MoveList struct is a simple wrapper around generate(). It sometimes comes
/// in handy to use this class instead of the low level generate() function.
template<GenType T>
struct MoveList {

explicit MoveList(const Position& pos) : last(generate<T>(pos, moveList)) {}

#ifdef USE_HEAP_INSTEAD_OF_STACK_FOR_MOVE_LIST
explicit MoveList(const Position& pos)
{
this->moveList = (ExtMove*)malloc(moveListSize);
if (this->moveList == 0)
{
printf("Error: Failed to allocate memory in heap.");
exit(1);
}
this->last = generate<T>(pos, this->moveList);
}

~MoveList()
{
free(this->moveList);
}
#else
explicit MoveList(const Position& pos) : last(generate<T>(pos, moveList))
{
;
}
#endif

const ExtMove* begin() const { return moveList; }
const ExtMove* end() const { return last; }
size_t size() const { return last - moveList; }
Expand All @@ -69,7 +102,12 @@ struct MoveList {
}

private:
ExtMove moveList[MAX_MOVES], *last;
ExtMove* last;
#ifdef USE_HEAP_INSTEAD_OF_STACK_FOR_MOVE_LIST
ExtMove* moveList = 0;
#else
ExtMove moveList[MAX_MOVES];
#endif
};

} // namespace Stockfish
Expand Down
Loading