Skip to content

Commit

Permalink
Merge remote-tracking branch 'ddugovic/master' into ddugovic
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Dec 13, 2017
2 parents e1e76da + eabe4fc commit ce4bdbb
Show file tree
Hide file tree
Showing 28 changed files with 1,945 additions and 441 deletions.
43 changes: 43 additions & 0 deletions deploy/appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
os: Visual Studio 2013

clone_folder: C:\projects\Stockfish
shallow_clone: true
clone_depth: 1

platform: x64

cache:
- x86_64-4.9.2-release-posix-seh-rt_v4-rev2.7z

install:
- cinst wget
- wget --no-clobber "http://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win64/Personal Builds/mingw-builds/4.9.2/threads-posix/seh/x86_64-4.9.2-release-posix-seh-rt_v4-rev2.7z"
- 7z x -oC:\MinGW\msys\1.0\ x86_64-4.9.2-release-posix-seh-rt_v4-rev2.7z > nul

build_script:
- C:\MinGW\msys\1.0\bin\sh.exe -c "cd /c/projects/Stockfish/; /c/projects/Stockfish/deploy/msys.sh"

artifacts:
- path: '*\stockfish-windows-*'

deploy:
- provider: S3
access_key_id:
secure: 1BWB8sb0ecF9242HMlKH54uFCn9GtjhxeaysqbVVDG4=
secret_access_key:
secure: l+Z1nugPzeV5fviFeckmfjjpvz7vfoALSMDt40Se77enlblgsr0/+/MrHQ+PMx/a
bucket: variant-stockfish
region: us-west-2
set_public: true
folder: ddugovic
artifact: /stockfish-windows-.*/
- provider: GitHub
release: $(APPVEYOR_REPO_TAG_NAME)
description: 'Multi-variant Stockfish binaries'
auth_token:
secure: HM1uS+Vhume4hO4gY5Ev8XU8rurfeviKBNbfu3xOrl3zWnKcsdAzkNA2JExElSAM
artifact: /stockfish-windows-.*/
draft: false
prerelease: false
on:
appveyor_repo_tag: true
47 changes: 47 additions & 0 deletions deploy/linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh -e

cd src

echo
echo "### Linker info"
echo
ldd --version || echo "no ldd"

echo
echo "### CPU capabilities"
echo
grep "^flags" /proc/cpuinfo || echo

echo
echo "### Running profile-build for x86-64 ..."
echo
make clean
make profile-build ARCH=x86-64 EXE=stockfish-x86_64

if [ -f /proc/cpuinfo ]; then
make clean
if grep "^flags" /proc/cpuinfo | grep -q popcnt ; then
echo
echo "### Running profile-build for x86-64-modern ..."
echo
make profile-build ARCH=x86-64-modern EXE=stockfish-x86_64-modern
else
echo
echo "### Running build for x86-64-modern ..."
echo
make build ARCH=x86-64-modern EXE=stockfish-x86_64-modern
fi

make clean
if grep "^flags" /proc/cpuinfo | grep popcnt | grep -q bmi2 ; then
echo
echo "### Running profile-build for x86-64-bmi2 ..."
echo
make profile-build ARCH=x86-64-bmi2 EXE=stockfish-x86_64-bmi2
else
echo
echo "### Running build for x86-64-bmi2 ..."
echo
make build ARCH=x86-64-bmi2 EXE=stockfish-x86_64-bmi2
fi
fi
24 changes: 24 additions & 0 deletions deploy/msys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

export PATH=.:/mingw64/bin:/usr/local/bin:/mingw/bin:/bin
export
mkdir "$APPVEYOR_REPO_BRANCH"

cd src

make clean
make profile-build COMP=mingw ARCH=x86-64
strip stockfish.exe
mv stockfish.exe "../$APPVEYOR_REPO_BRANCH/stockfish-windows-x86_64.exe"

make clean
make profile-build COMP=mingw ARCH=x86-64-modern
strip stockfish.exe
mv stockfish.exe "../$APPVEYOR_REPO_BRANCH/stockfish-windows-x86_64-modern.exe"

make clean
make profile-build COMP=mingw ARCH=x86-64-bmi2
strip stockfish.exe
mv stockfish.exe "../$APPVEYOR_REPO_BRANCH/stockfish-windows-x86_64-bmi2.exe"

cd ..
13 changes: 13 additions & 0 deletions deploy/old-gcc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/thread.h b/src/thread.h
index 3aa5bb51..ac72d15d 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -84,7 +84,7 @@ public:

struct MainThread : public Thread {

- using Thread::Thread;
+ explicit MainThread(size_t n) : Thread(n) { }

void search() override;
void check_time();
7 changes: 7 additions & 0 deletions deploy/wheezy.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM debian:wheezy
RUN apt-get update && apt-get install -y make g++
VOLUME /home/builder/Stockfish
WORKDIR /home/builder/Stockfish
RUN groupadd -r builder && useradd -r -g builder builder
USER builder
CMD ./deploy/linux.sh
23 changes: 20 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Stockfish, a UCI chess playing engine derived from Glaurung 2.1
# Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
# Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
# Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
# Copyright (C) 2015-2017 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
#
# Stockfish is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -141,7 +141,7 @@ endif

### 3.1 Selecting compiler (default = gcc)

CXXFLAGS += -Wall -Wcast-qual -std=c++11 $(EXTRACXXFLAGS)
CXXFLAGS += -Wall -Wcast-qual -fno-exceptions -std=c++11 $(EXTRACXXFLAGS)
DEPENDFLAGS += -std=c++11
LDFLAGS += $(EXTRALDFLAGS)

Expand Down Expand Up @@ -205,7 +205,9 @@ ifeq ($(COMP),clang)
CXX=clang++
CXXFLAGS += -pedantic -Wextra -Wshadow
ifneq ($(KERNEL),Darwin)
ifneq ($(KERNEL),OpenBSD)
LDFLAGS += -latomic
endif
endif

ifeq ($(ARCH),armv7)
Expand Down Expand Up @@ -259,22 +261,37 @@ ifneq ($(comp),mingw)
endif

### 3.2.1 Debugging
CXXFLAGS += -DANTI -DATOMIC -DBUGHOUSE -DCRAZYHOUSE -DHORDE -DKOTH -DLOOP -DLOSERS -DRACE -DSKILL -DSUICIDE -DTHREECHECK -DUSELONGESTPV
CXXFLAGS += -DANTI -DATOMIC -DBUGHOUSE -DCRAZYHOUSE -DDISPLACEDGRID -DEXTINCTION -DGRID -DHORDE -DKOTH -DLOOP -DLOSERS -DRACE -DSKILL -DSLIPPEDGRID -DSUICIDE -DTHREECHECK -DTWOKINGS -DTWOKINGSSYMMETRIC -DUSELONGESTPV
ifneq (,$(filter -DBUGHOUSE,$(CXXFLAGS)))
ifeq (,$(filter -DCRAZYHOUSE,$(CXXFLAGS)))
$(error Crazyhouse (-DCRAZYHOUSE) is required for subvariant bughouse chess)
endif
endif
ifneq (,$(filter -DDISPLACEDGRID,$(CXXFLAGS)))
ifeq (,$(filter -DGRID,$(CXXFLAGS)))
$(error Grid (-GRID) is required for subvariant displaced grid)
endif
endif
ifneq (,$(filter -DLOOP,$(CXXFLAGS)))
ifeq (,$(filter -DCRAZYHOUSE,$(CXXFLAGS)))
$(error Crazyhouse (-DCRAZYHOUSE) is required for subvariant loop chess)
endif
endif
ifneq (,$(filter -DSLIPPEDGRID,$(CXXFLAGS)))
ifeq (,$(filter -DGRID,$(CXXFLAGS)))
$(error Grid (-GRID) is required for subvariant slipped grid)
endif
endif
ifneq (,$(filter -DSUICIDE,$(CXXFLAGS)))
ifeq (,$(filter -DANTI,$(CXXFLAGS)))
$(error Giveaway (-DANTI) is required for subvariant suicide chess)
endif
endif
ifneq (,$(filter -DTWOKINGSSYMMETRIC,$(CXXFLAGS)))
ifeq (,$(filter -DTWOKINGS,$(CXXFLAGS)))
$(error Twokings (-TWOKINGS) is required for subvariant twokingssymmetric)
endif
endif
ifeq ($(debug),no)
CXXFLAGS += -DNDEBUG
else
Expand Down
2 changes: 1 addition & 1 deletion src/bitbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace {
ksq[WHITE] = Square((idx >> 0) & 0x3F);
ksq[BLACK] = Square((idx >> 6) & 0x3F);
us = Color ((idx >> 12) & 0x01);
psq = make_square(File((idx >> 13) & 0x3), RANK_7 - Rank((idx >> 15) & 0x7));
psq = make_square(File((idx >> 13) & 0x3), Rank(RANK_7 - ((idx >> 15) & 0x7)));

// Check if two pieces are on the same square or if a king can be captured
if ( distance(ksq[WHITE], ksq[BLACK]) <= 1
Expand Down
53 changes: 40 additions & 13 deletions src/bitboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
#ifdef GRID
Bitboard GridBB[GRIDLAYOUT_NB][SQUARE_NB];
#endif

Magic RookMagics[SQUARE_NB];
Magic BishopMagics[SQUARE_NB];
Expand All @@ -54,7 +57,7 @@ namespace {
Bitboard RookTable[0x19000]; // To store rook attacks
Bitboard BishopTable[0x1480]; // To store bishop attacks

void init_magics(Bitboard table[], Magic magics[], Square deltas[]);
void init_magics(Bitboard table[], Magic magics[], Direction directions[]);

// bsf_index() returns the index into BSFTable[] to look up the bitscan. Uses
// Matt Taylor's folding for 32 bit case, extended to 64 bit by Kim Walisch.
Expand Down Expand Up @@ -188,7 +191,7 @@ void Bitboards::init() {
for (Square s = SQ_A1; s <= SQ_H8; ++s)
for (int i = 0; steps[pt][i]; ++i)
{
Square to = s + Square(c == WHITE ? steps[pt][i] : -steps[pt][i]);
Square to = s + Direction(c == WHITE ? steps[pt][i] : -steps[pt][i]);

if (is_ok(to) && distance(s, to) < 3)
{
Expand All @@ -199,11 +202,11 @@ void Bitboards::init() {
}
}

Square RookDeltas[] = { NORTH, EAST, SOUTH, WEST };
Square BishopDeltas[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST };
Direction RookDirections[] = { NORTH, EAST, SOUTH, WEST };
Direction BishopDirections[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST };

init_magics(RookTable, RookMagics, RookDeltas);
init_magics(BishopTable, BishopMagics, BishopDeltas);
init_magics(RookTable, RookMagics, RookDirections);
init_magics(BishopTable, BishopMagics, BishopDirections);

for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
{
Expand All @@ -220,19 +223,43 @@ void Bitboards::init() {
BetweenBB[s1][s2] = attacks_bb(pt, s1, SquareBB[s2]) & attacks_bb(pt, s2, SquareBB[s1]);
}
}

#ifdef GRID
for (Square s = SQ_A1; s <= SQ_H8; ++s)
{
GridBB[NORMAL_GRID][s] = SquareBB[s] | SquareBB[s ^ 8] | SquareBB[s ^ 1] | SquareBB[s ^ 9];
#ifdef DISPLACEDGRID
GridBB[DISPLACED_GRID][s] = SquareBB[s];
if (!((FileABB | FileHBB) & s))
GridBB[DISPLACED_GRID][s] |= SquareBB[((s + 1) ^ 1) - 1];
if (!((Rank1BB | Rank8BB) & s))
GridBB[DISPLACED_GRID][s] |= SquareBB[((s + 8) ^ 8) - 8];
if (!((Rank1BB | Rank8BB | FileABB | FileHBB) & s))
GridBB[DISPLACED_GRID][s] |= SquareBB[((s + 9) ^ 9) - 9];
#endif
#ifdef SLIPPEDGRID
GridBB[SLIPPED_GRID][s] = SquareBB[s] | SquareBB[s ^ 8];
if (!((FileABB | FileHBB) & s))
{
GridBB[SLIPPED_GRID][s] |= SquareBB[((s + 1) ^ 1) - 1];
GridBB[SLIPPED_GRID][s] |= SquareBB[(((s + 1) ^ 1) - 1) ^ 8];
}
#endif
}
#endif
}


namespace {

Bitboard sliding_attack(Square deltas[], Square sq, Bitboard occupied) {
Bitboard sliding_attack(Direction directions[], Square sq, Bitboard occupied) {

Bitboard attack = 0;

for (int i = 0; i < 4; ++i)
for (Square s = sq + deltas[i];
is_ok(s) && distance(s, s - deltas[i]) == 1;
s += deltas[i])
for (Square s = sq + directions[i];
is_ok(s) && distance(s, s - directions[i]) == 1;
s += directions[i])
{
attack |= s;

Expand All @@ -249,7 +276,7 @@ namespace {
// chessprogramming.wikispaces.com/Magic+Bitboards. In particular, here we
// use the so called "fancy" approach.

void init_magics(Bitboard table[], Magic magics[], Square deltas[]) {
void init_magics(Bitboard table[], Magic magics[], Direction directions[]) {

// Optimal PRNG seeds to pick the correct magics in the shortest time
int seeds[][RANK_NB] = { { 8977, 44560, 54343, 38998, 5731, 95205, 104912, 17020 },
Expand All @@ -269,7 +296,7 @@ namespace {
// the number of 1s of the mask. Hence we deduce the size of the shift to
// apply to the 64 or 32 bits word to get the index.
Magic& m = magics[s];
m.mask = sliding_attack(deltas, s, 0) & ~edges;
m.mask = sliding_attack(directions, s, 0) & ~edges;
m.shift = (Is64Bit ? 64 : 32) - popcount(m.mask);

// Set the offset for the attacks table of the square. We have individual
Expand All @@ -281,7 +308,7 @@ namespace {
b = size = 0;
do {
occupancy[size] = b;
reference[size] = sliding_attack(deltas, s, b);
reference[size] = sliding_attack(directions, s, b);

if (HasPext)
m.attacks[pext(b, m.mask)] = reference[size];
Expand Down
16 changes: 12 additions & 4 deletions src/bitboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ extern Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
extern Bitboard PawnAttackSpan[COLOR_NB][SQUARE_NB];
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
extern Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
#ifdef GRID
extern Bitboard GridBB[GRIDLAYOUT_NB][SQUARE_NB];
#endif


/// Magic holds all magic bitboards relevant data for a single square
Expand Down Expand Up @@ -134,11 +137,10 @@ inline Bitboard& operator-=(Bitboard& b, Square s) {
return b &= ~SquareBB[s];
}

inline bool more_than_one(Bitboard b) {
constexpr bool more_than_one(Bitboard b) {
return b & (b - 1);
}


/// rank_bb() and file_bb() return a bitboard representing all the squares on
/// the given file or rank.

Expand All @@ -158,11 +160,17 @@ inline Bitboard file_bb(Square s) {
return FileBB[file_of(s)];
}

#ifdef GRID
inline Bitboard grid_layout_bb(GridLayout l, Square s) {
return GridBB[l][s];
}
#endif


/// shift() moves a bitboard one step along direction D. Mainly for pawns

template<Square D>
inline Bitboard shift(Bitboard b) {
template<Direction D>
constexpr Bitboard shift(Bitboard b) {
return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
: D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == SOUTH_EAST ? (b & ~FileHBB) >> 7
: D == NORTH_WEST ? (b & ~FileABB) << 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
Expand Down
2 changes: 1 addition & 1 deletion src/endgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ ScaleFactor Endgame<CHESS_VARIANT, KRPKB>::operator()(const Position& pos) const
Square bsq = pos.square<BISHOP>(weakSide);
Square psq = pos.square<PAWN>(strongSide);
Rank rk = relative_rank(strongSide, psq);
Square push = pawn_push(strongSide);
Direction push = pawn_push(strongSide);

// If the pawn is on the 5th rank and the pawn (currently) is on
// the same color square as the bishop then there is a chance of
Expand Down
Loading

0 comments on commit ce4bdbb

Please sign in to comment.