Skip to content

Commit

Permalink
Fix problems in Atomic, and adapt to SFNNv7 possibly SFNNv8 in the fu…
Browse files Browse the repository at this point in the history
…ture
  • Loading branch information
chocolatebakery authored and ddugovic committed Jul 3, 2024
1 parent 89284f6 commit 8a59ec9
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 9 deletions.
75 changes: 75 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"files.associations": {
"algorithm": "cpp",
"bitset": "cpp",
"iterator": "cpp",
"xhash": "cpp",
"xmemory": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"deque": "cpp",
"exception": "cpp",
"format": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"set": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"utility": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xstring": "cpp",
"xtr1common": "cpp"
}
}
42 changes: 37 additions & 5 deletions src/movegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "movegen.h"
#include "position.h"
#include "uci.h"

namespace Stockfish {

Expand Down Expand Up @@ -224,10 +225,29 @@ namespace {
#ifdef ATOMIC
if constexpr (V == ATOMIC_VARIANT)
{
b1 &= (Type == CAPTURES || Type == NON_EVASIONS) ? target : ~adjacent_squares_bb(pos.pieces(Us, KING));
b2 &= (Type == CAPTURES || Type == NON_EVASIONS) ? target : ~adjacent_squares_bb(pos.pieces(Us, KING));
//b1 &= (Type == CAPTURES || Type == NON_EVASIONS) ? target : ~adjacent_squares_bb(pos.pieces(Us, KING));
//b2 &= (Type == CAPTURES || Type == NON_EVASIONS) ? target : ~adjacent_squares_bb(pos.pieces(Us, KING));
if (Type == EVASIONS) {
b1 = shift<UpRight>(pawnsOn7) & ~adjacent_squares_bb(pos.pieces(Us, KING)) & target & pos.pieces(Them);
b2 = shift<UpLeft >(pawnsOn7) & ~adjacent_squares_bb(pos.pieces(Us, KING)) & target & pos.pieces(Them);
}
else if (Type == CAPTURES) {
b1 = shift<UpRight>(pawnsOn7) & target;
b2 = shift<UpLeft >(pawnsOn7) & target;
}
else if (Type == NON_EVASIONS) {
b1 = shift<UpRight>(pawnsOn7) & target & pos.pieces(Them);
b2 = shift<UpLeft >(pawnsOn7) & target & pos.pieces(Them);
}
}
#endif

#ifdef ATOMIC
// Promotes only if promotion wins or explodes checkers
if (V == ATOMIC_VARIANT && pos.checkers())
b3 = shift<Up >(pawnsOn7) & emptySquares & target;
#endif

#ifdef ANTI
if constexpr (V == ANTI_VARIANT)
b3 &= target;
Expand Down Expand Up @@ -257,10 +277,22 @@ namespace {
#ifdef ATOMIC
if constexpr (V == ATOMIC_VARIANT)
{
b1 &= (Type == CAPTURES || Type == NON_EVASIONS) ? target : ~adjacent_squares_bb(pos.pieces(Us, KING));
b2 &= (Type == CAPTURES || Type == NON_EVASIONS) ? target : ~adjacent_squares_bb(pos.pieces(Us, KING));
//b1 &= (Type == CAPTURES || Type == NON_EVASIONS) ? target : ~adjacent_squares_bb(pos.pieces(Us, KING));
//b2 &= (Type == CAPTURES || Type == NON_EVASIONS) ? target : ~adjacent_squares_bb(pos.pieces(Us, KING));
if (Type == EVASIONS) {
b1 = shift<UpRight>(pawnsNotOn7) & ~adjacent_squares_bb(pos.pieces(Us, KING)) & target & pos.pieces(Them);
b2 = shift<UpLeft >(pawnsNotOn7) & ~adjacent_squares_bb(pos.pieces(Us, KING)) & target & pos.pieces(Them);
}
else if (Type == CAPTURES) {
b1 = shift<UpRight>(pawnsNotOn7) & target;
b2 = shift<UpLeft >(pawnsNotOn7) & target;
}
else if (Type == NON_EVASIONS) {
b1 = shift<UpRight>(pawnsNotOn7) & target & pos.pieces(Them);
b2 = shift<UpLeft >(pawnsNotOn7) & target & pos.pieces(Them);
}
}
#endif
#endif

while (b1)
{
Expand Down
1 change: 1 addition & 0 deletions src/nnue/layers/affine_transform_sparse_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "../nnue_common.h"
#include "affine_transform.h"
#include "simd.h"
#include "../../bitboard.h"

/*
This file contains the definition for a fully connected layer (aka affine transform) with block sparse input.
Expand Down
15 changes: 11 additions & 4 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ bool Position::legal(Move m) const {
Color us = sideToMove;
Square from = from_sq(m);
Square to = to_sq(m);

assert(color_of(moved_piece(m)) == us);
#ifdef ANTI
// If a player can capture, that player must capture
Expand Down Expand Up @@ -1255,10 +1255,15 @@ bool Position::pseudo_legal(const Move m) const {
return true;
if (capture(m))
{

//Square capsq = type_of(m) == EN_PASSANT ? make_square(file_of(to), rank_of(from)) : to;
// Capturing the opposing king or all checking pieces suffices.
Bitboard blast = attacks_bb(KING, to, 0) & (pieces() ^ pieces(PAWN));
//Bitboard b = pieces() ^ ((blast | capsq) | from);

if ((blast & square<KING>(~us)) || ~(checkers() & blast))
return true;

}
}
#endif
Expand Down Expand Up @@ -1419,6 +1424,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {

assert(is_ok(m));
assert(&newSt != st);

#ifdef ANTI
assert(!is_anti() || !givesCheck);
#endif
Expand Down Expand Up @@ -1714,8 +1720,9 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
{
if (Eval::useNNUE)
{
dp.from[0] = SQ_NONE;
dp.piece[0] = pc;
dp.to[0] = SQ_NONE;
dp.from[0] = from;
}
remove_piece(from);
// Update material (hash key already updated)
Expand Down Expand Up @@ -2254,7 +2261,7 @@ bool Position::see_ge(Move m, Bitboard& occupied, Value threshold) const {
if (threshold > VALUE_ZERO)
return false;

Bitboard occupied = pieces() ^ from;
occupied = pieces() ^ from;
Bitboard attackers = attackers_to(to, occupied) & occupied & pieces(~stm) & ~pieces(KING);

// Loop over attacking pieces
Expand Down Expand Up @@ -2282,7 +2289,7 @@ bool Position::see_ge(Move m, Bitboard& occupied, Value threshold) const {
if (is_extinction() && ! more_than_one(pieces(color_of(piece_on(from)), type_of(piece_on(from)))))
{
// Toggles to square occupancy in case of stm != sideToMove
Bitboard occupied = pieces() ^ from ^ to;
occupied = pieces() ^ from ^ to;
if (type_of(m) == EN_PASSANT)
occupied ^= make_square(file_of(to), rank_of(from));
if (attackers_to(to, occupied) & occupied & pieces(color_of(piece_on(from))))
Expand Down

0 comments on commit 8a59ec9

Please sign in to comment.