Skip to content

Commit

Permalink
Merge branch 'master' into wallormove
Browse files Browse the repository at this point in the history
  • Loading branch information
RainRat authored Dec 31, 2023
2 parents 3d1ad60 + cf75709 commit 39279bd
Show file tree
Hide file tree
Showing 15 changed files with 446 additions and 199 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
- uses: actions/setup-python@v3

- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.11.2
run: python -m pip install cibuildwheel==2.16.2

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
# to supply options, put them in 'env', like:
env:
MACOSX_DEPLOYMENT_TARGET: "10.14"
CIBW_ARCHS_MACOS: "x86_64 arm64"
CIBW_SKIP: "pp* *-win32 *-manylinux_i686 *-musllinux_* cp36-*"
CIBW_SKIP: "pp* *-win32 *-manylinux_i686 *-musllinux_* cp36-* cp37-*"
CIBW_TEST_COMMAND: python {project}/test.py

- uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ build_script:
$dummy = $nnuenet -match "(?<nnuenet>nn-[a-z0-9]{12}.nnue)"
$nnuenet = $Matches.nnuenet
Write-Host "Default net:" $nnuenet
$nnuedownloadurl = "https://tests.stockfishchess.org/api/nn/$nnuenet"
$nnuedownloadurl = "https://github.com/official-stockfish/networks/raw/master/$nnuenet"
$nnuefilepath = "src\${env:CONFIGURATION}\$nnuenet"
if (Test-Path -Path $nnuefilepath) {
Write-Host "Already available."
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
sources=sources,
extra_compile_args=args)

setup(name="pyffish", version="0.0.78",
setup(name="pyffish", version="0.0.80",
description="Fairy-Stockfish Python wrapper",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
40 changes: 25 additions & 15 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -821,25 +821,35 @@ clean: objclean profileclean
net:
$(eval nnuenet := $(shell grep EvalFileDefaultName evaluate.h | grep define | sed 's/.*\(nn-[a-z0-9]\{12\}.nnue\).*/\1/'))
@echo "Default net: $(nnuenet)"
$(eval nnuedownloadurl := https://tests.stockfishchess.org/api/nn/$(nnuenet))
$(eval nnuedownloadurl1 := https://tests.stockfishchess.org/api/nn/$(nnuenet))
$(eval nnuedownloadurl2 := https://github.com/official-stockfish/networks/raw/master/$(nnuenet))
$(eval curl_or_wget := $(shell if hash curl 2>/dev/null; then echo "curl -skL"; elif hash wget 2>/dev/null; then echo "wget -qO-"; fi))
@if test -f "$(nnuenet)"; then \
echo "Already available."; \
else \
if [ "x$(curl_or_wget)" = "x" ]; then \
echo "Automatic download failed: neither curl nor wget is installed. Install one of these tools or download the net manually"; exit 1; \
else \
echo "Downloading $(nnuedownloadurl)"; $(curl_or_wget) $(nnuedownloadurl) > $(nnuenet);\
fi; \
fi;
@if [ "x$(curl_or_wget)" = "x" ]; then \
echo "Automatic download failed: neither curl nor wget is installed. Install one of these tools or download the net manually"; exit 1; \
fi
$(eval shasum_command := $(shell if hash shasum 2>/dev/null; then echo "shasum -a 256 "; elif hash sha256sum 2>/dev/null; then echo "sha256sum "; fi))
@if [ "x$(shasum_command)" != "x" ]; then \
if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
echo "Failed download or $(nnuenet) corrupted, please delete!"; exit 1; \
fi \
else \
@if [ "x$(shasum_command)" = "x" ]; then \
echo "shasum / sha256sum not found, skipping net validation"; \
fi
@for nnuedownloadurl in "$(nnuedownloadurl1)" "$(nnuedownloadurl2)"; do \
if test -f "$(nnuenet)"; then \
echo "$(nnuenet) available."; \
else \
if [ "x$(curl_or_wget)" != "x" ]; then \
echo "Downloading $${nnuedownloadurl}"; $(curl_or_wget) $${nnuedownloadurl} > $(nnuenet);\
fi; \
fi; \
if [ "x$(shasum_command)" != "x" ]; then \
if [ "$(nnuenet)" != "nn-"`$(shasum_command) $(nnuenet) | cut -c1-12`".nnue" ]; then \
echo "Removing failed download"; rm -f $(nnuenet); \
else \
echo "Network validated"; break; \
fi; \
fi; \
done
@if ! test -f "$(nnuenet)"; then \
echo "Failed to download $(nnuenet)."; \
fi

# clean binaries and objects
objclean:
Expand Down
4 changes: 2 additions & 2 deletions src/movegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ namespace {
}

// Workaround for passing: Execute a non-move with any piece
if (pos.pass() && !pos.count<KING>(Us) && pos.pieces(Us))
if (pos.pass(Us) && !pos.count<KING>(Us) && pos.pieces(Us))
*moveList++ = make<SPECIAL>(lsb(pos.pieces(Us)), lsb(pos.pieces(Us)));

//if "wall or move", generate walling action with null move
Expand All @@ -461,7 +461,7 @@ namespace {
moveList = make_move_and_gating<NORMAL>(pos, moveList, Us, ksq, pop_lsb(b));

// Passing move by king
if (pos.pass())
if (pos.pass(Us))
*moveList++ = make<SPECIAL>(ksq, ksq);

if ((Type == QUIETS || Type == NON_EVASIONS) && pos.can_castle(Us & ANY_CASTLING))
Expand Down
56 changes: 47 additions & 9 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ namespace {
: value == "ataxx" ? ATAXX
: value == "quadwrangle" ? QUADWRANGLE
: value == "snort" ? SNORT
: value == "anyside" ? ANYSIDE
: value == "top" ? TOP
: NO_ENCLOSING;
return value == "reversi" || value == "ataxx" || value == "quadwrangle" || value =="snort" || value == "none";
return value == "reversi" || value == "ataxx" || value == "quadwrangle" || value =="snort" || value =="anyside" || value =="top" || value == "none";
}

template <> bool set(const std::string& value, WallingRule& target) {
Expand All @@ -122,19 +124,36 @@ namespace {
}

template <> bool set(const std::string& value, Bitboard& target) {
char file;
int rank;
std::string symbol;
std::stringstream ss(value);
target = 0;
while (!ss.eof() && ss >> file && file != '-' && ss >> rank)
while (!ss.eof() && ss >> symbol && symbol != "-")
{
if (Rank(rank - 1) > RANK_MAX || (file != '*' && File(tolower(file) - 'a') > FILE_MAX))
if (symbol.back() == '*') {
if (isalpha(symbol[0]) && symbol.length() == 2) {
char file = tolower(symbol[0]);
if (File(file - 'a') > FILE_MAX) return false;
target |= file_bb(File(file - 'a'));
} else {
return false;
}
} else if (symbol[0] == '*') {
int rank = std::stoi(symbol.substr(1));
if (Rank(rank - 1) > RANK_MAX) return false;
target |= rank_bb(Rank(rank - 1));
} else if (isalpha(symbol[0]) && symbol.length() > 1) {
char file = tolower(symbol[0]);
int rank = std::stoi(symbol.substr(1));
if (Rank(rank - 1) > RANK_MAX || File(file - 'a') > FILE_MAX) return false;
target |= square_bb(make_square(File(file - 'a'), Rank(rank - 1)));
} else {
return false;
target |= file == '*' ? rank_bb(Rank(rank - 1)) : square_bb(make_square(File(tolower(file) - 'a'), Rank(rank - 1)));
}
}
return !ss.fail();
}


template <> bool set(const std::string& value, CastlingRights& target) {
char c;
CastlingRights castlingRight;
Expand Down Expand Up @@ -327,6 +346,10 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
parse_attribute<false>("castlingRookPiece", v->castlingRookPieces[WHITE], v->pieceToChar);
parse_attribute<false>("castlingRookPiece", v->castlingRookPieces[BLACK], v->pieceToChar);

bool dropOnTop = false;
parse_attribute<false>("dropOnTop", dropOnTop);
if (dropOnTop) v->enclosingDrop=TOP;

// Parse aliases
parse_attribute("pawnTypes", v->promotionPawnType[WHITE], v->pieceToChar);
parse_attribute("pawnTypes", v->promotionPawnType[BLACK], v->pieceToChar);
Expand Down Expand Up @@ -433,7 +456,6 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
parse_attribute("capturesToHand", v->capturesToHand);
parse_attribute("firstRankPawnDrops", v->firstRankPawnDrops);
parse_attribute("promotionZonePawnDrops", v->promotionZonePawnDrops);
parse_attribute("dropOnTop", v->dropOnTop);
parse_attribute("enclosingDrop", v->enclosingDrop);
parse_attribute("enclosingDropStart", v->enclosingDropStart);
parse_attribute("whiteDropRegion", v->whiteDropRegion);
Expand All @@ -454,8 +476,14 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
parse_attribute("seirawanGating", v->seirawanGating);
parse_attribute("cambodianMoves", v->cambodianMoves);
parse_attribute("diagonalLines", v->diagonalLines);
parse_attribute("pass", v->pass);
parse_attribute("passOnStalemate", v->passOnStalemate);
parse_attribute("pass", v->pass[WHITE]);
parse_attribute("pass", v->pass[BLACK]);
parse_attribute("passWhite", v->pass[WHITE]);
parse_attribute("passBlack", v->pass[BLACK]);
parse_attribute("passOnStalemate", v->passOnStalemate[WHITE]);
parse_attribute("passOnStalemate", v->passOnStalemate[BLACK]);
parse_attribute("passOnStalemateWhite", v->passOnStalemate[WHITE]);
parse_attribute("passOnStalemateBlack", v->passOnStalemate[BLACK]);
parse_attribute("makpongRule", v->makpongRule);
parse_attribute("flyingGeneral", v->flyingGeneral);
parse_attribute("soldierPromotionRank", v->soldierPromotionRank);
Expand Down Expand Up @@ -497,12 +525,20 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
parse_attribute("flagPieceCount", v->flagPieceCount);
parse_attribute("flagPieceBlockedWin", v->flagPieceBlockedWin);
parse_attribute("flagMove", v->flagMove);
parse_attribute("flagPieceSafe", v->flagPieceSafe);
parse_attribute("checkCounting", v->checkCounting);
parse_attribute("connectN", v->connectN);
parse_attribute("connectHorizontal", v->connectHorizontal);
parse_attribute("connectVertical", v->connectVertical);
parse_attribute("connectDiagonal", v->connectDiagonal);
parse_attribute("connectRegion1White", v->connectRegion1[WHITE]);
parse_attribute("connectRegion2White", v->connectRegion2[WHITE]);
parse_attribute("connectRegion1Black", v->connectRegion1[BLACK]);
parse_attribute("connectRegion2Black", v->connectRegion2[BLACK]);
parse_attribute("connectNxN", v->connectNxN);
parse_attribute("connectValue", v->connectValue);
parse_attribute("materialCounting", v->materialCounting);
parse_attribute("adjudicateFullBoard", v->adjudicateFullBoard);
parse_attribute("countingRule", v->countingRule);
parse_attribute("castlingWins", v->castlingWins);

Expand Down Expand Up @@ -599,6 +635,8 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
if (v->mutuallyImmuneTypes)
std::cerr << "Can not use kings or pseudo-royal with mutuallyImmuneTypes." << std::endl;
}
if (v->flagPieceSafe && v->blastOnCapture)
std::cerr << "Can not use flagPieceSafe with blastOnCapture (flagPieceSafe uses simple assessment that does not see blast)." << std::endl;
}
return v;
}
Expand Down
56 changes: 49 additions & 7 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ bool Position::legal(Move m) const {
return false;

// Illegal king passing move
if (pass_on_stalemate() && is_pass(m) && !checkers())
if (pass_on_stalemate(us) && is_pass(m) && !checkers())
{
for (const auto& move : MoveList<NON_EVASIONS>(*this))
if (!is_pass(move) && legal(move))
Expand Down Expand Up @@ -1558,7 +1558,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
Piece captured = piece_on(type_of(m) == EN_PASSANT ? capture_square(to) : to);
if (to == from)
{
assert((type_of(m) == PROMOTION && sittuyin_promotion()) || (is_pass(m) && pass()));
assert((type_of(m) == PROMOTION && sittuyin_promotion()) || (is_pass(m) && pass(us)));
captured = NO_PIECE;
}
st->capturedpromoted = is_promoted(to);
Expand Down Expand Up @@ -2128,7 +2128,7 @@ void Position::undo_move(Move m) {

assert(type_of(m) == DROP || empty(from) || type_of(m) == CASTLING || is_gating(m)
|| (type_of(m) == PROMOTION && sittuyin_promotion())
|| (is_pass(m) && pass()));
|| (is_pass(m) && pass(us)));
assert(type_of(st->capturedPiece) != KING);

// Reset wall squares
Expand Down Expand Up @@ -2566,7 +2566,7 @@ bool Position::see_ge(Move m, Value threshold) const {
return bool(res);
}

/// Position::is_optinal_game_end() tests whether the position may end the game by
/// Position::is_optional_game_end() tests whether the position may end the game by
/// 50-move rule, by repetition, or a variant rule that allows a player to claim a game result.

bool Position::is_optional_game_end(Value& result, int ply, int countStarted) const {
Expand Down Expand Up @@ -2803,23 +2803,65 @@ bool Position::is_immediate_game_end(Value& result, int ply) const {
b &= shift(d, b);
if (b)
{
result = mated_in(ply);
result = convert_mate_value(-var->connectValue, ply);
return true;
}
}
}
// Check for bikjang rule (Janggi) and double passing
if (st->pliesFromNull > 0 && ((st->bikjang && st->previous->bikjang) || (st->pass && st->previous->pass)))

if ((var->connectRegion1[~sideToMove] & pieces(~sideToMove)) && (var->connectRegion2[~sideToMove] & pieces(~sideToMove)))
{
Bitboard target = var->connectRegion2[~sideToMove];
Bitboard current = var->connectRegion1[~sideToMove] & pieces(~sideToMove);

while (true) {
Bitboard newBitboard = 0;
for (Direction d : var->connect_directions) {
newBitboard |= shift(d, current | newBitboard) & pieces(~sideToMove); // the "| newBitboard" here probably saves a few loops
}

if (newBitboard & target) {
// A connection has been made
result = convert_mate_value(-var->connectValue, ply);
return true;
}

if (!(newBitboard & ~current)) {
// The expansion got stuck; no further squares to explore
break;
}

current |= newBitboard;
}
}

if (connect_nxn())
{
Bitboard connectors = pieces(~sideToMove);
for (int i = 1; i < connect_nxn() && connectors; i++)
connectors &= shift<SOUTH>(connectors) & shift<EAST>(connectors) & shift<SOUTH_EAST>(connectors);
if (connectors)
{
result = convert_mate_value(-var->connectValue, ply);
return true;
}
}

// Check for bikjang rule (Janggi), double passing, or board running full
if ( (st->pliesFromNull > 0 && ((st->bikjang && st->previous->bikjang) || (st->pass && st->previous->pass)))
|| (var->adjudicateFullBoard && !(~pieces() & board_bb())))
{
result = var->materialCounting ? convert_mate_value(material_counting_result(), ply) : VALUE_DRAW;
return true;
}

// Tsume mode: Assume that side with king wins when not in check
if (tsumeMode && !count<KING>(~sideToMove) && count<KING>(sideToMove) && !checkers())
{
result = mate_in(ply);
return true;
}

// Failing to checkmate with virtual pieces is a loss
if (two_boards() && !checkers())
{
Expand Down
Loading

0 comments on commit 39279bd

Please sign in to comment.