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

Search Refactor & Verification #27

Merged
merged 46 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
faca376
Keep track of moves made.
bsamseth Feb 10, 2019
35b4fb7
Bugfix: Be more restrictive about using NMP
bsamseth Feb 10, 2019
2dc3f8c
Repeal aspiration window search.
bsamseth Feb 11, 2019
d1471b8
Only do NMP when eval indicates it.
bsamseth Feb 11, 2019
59c2290
Store mate/draw with current depth, not MAX.
bsamseth Feb 11, 2019
4eb5220
Clean up bound determining in search
bsamseth Feb 11, 2019
9375007
Fix unused variable warning.
bsamseth Feb 11, 2019
10429da
Add puzzle tests for search verification.
bsamseth Feb 11, 2019
f27766b
Update puzzle tests to play nice with unittest
bsamseth Feb 11, 2019
1e11ed6
Set up build dir smart if no dir is present.
bsamseth Feb 11, 2019
d17a96c
Add search verification to CI
bsamseth Feb 11, 2019
cf40f0a
Fix CI
bsamseth Feb 11, 2019
37d2a22
Non-functional change
bsamseth Feb 11, 2019
b1f28b2
Fix update_search calls
bsamseth Feb 12, 2019
2afe4a1
Store correct depth for null value entries
bsamseth Feb 12, 2019
5ed86d4
Change search limits in puzzles.
bsamseth Feb 12, 2019
2919e7d
Fix bug in multi-variation mate distance puzzle
bsamseth Feb 12, 2019
da91cca
Attempt to fix sudden abort due to update_search
bsamseth Feb 12, 2019
5d829e4
Revert update_search confusion
bsamseth Feb 12, 2019
735bd53
Remove all optimization in debug mode.
bsamseth Feb 12, 2019
7e11573
Consolidate bound type assignment
bsamseth Feb 12, 2019
dc4971f
Simplify ttable lookup logic
bsamseth Feb 12, 2019
bc6f96b
Allow Bound to be used as integer
bsamseth Feb 12, 2019
5bc5838
Bugfix: Consistent retrieval of mates form tt
bsamseth Feb 12, 2019
117241f
Add optional debug logging to puzzle tests.
bsamseth Feb 12, 2019
13ac30e
Add more puzzles to search verification.
bsamseth Feb 12, 2019
52a267b
Include search verification in coverage report.
bsamseth Feb 12, 2019
b785278
Use make target for bench in CI
bsamseth Feb 12, 2019
f0edccf
Fix CI
bsamseth Feb 12, 2019
476352f
Don't zero coverage counters.
bsamseth Feb 12, 2019
621d677
Add upload to codecov
bsamseth Feb 12, 2019
2ecba25
Add codecov badge to README
bsamseth Feb 12, 2019
44d265b
Fragment src/search.cpp
bsamseth Feb 12, 2019
d542035
Add new source files to source list.
bsamseth Feb 12, 2019
2560c62
Split out PVS as separate function.
bsamseth Feb 12, 2019
96c0ef9
Add non-mate test positions to search verification
bsamseth Feb 12, 2019
bae0cd1
Bench before calculating coverage
bsamseth Feb 12, 2019
4be34ed
Update todo-list
bsamseth Feb 12, 2019
3aa38ee
Add tests of node- and time limited search.
bsamseth Feb 12, 2019
4b0f8c1
Add pipfile to handle python deps
bsamseth Feb 12, 2019
909a37c
Add test for playing matches.
bsamseth Feb 12, 2019
5ada898
Bump version number to v1.9.0
bsamseth Feb 13, 2019
349ecbf
Fix bug with move_count implementation.
bsamseth Feb 13, 2019
13bc0b1
Remove unused import
bsamseth Feb 14, 2019
807eb58
Update chester dep to v0.2.1
bsamseth Feb 15, 2019
a56b2f8
Add games for v1.9.0
bsamseth Feb 15, 2019
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
31 changes: 25 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
language: cpp
compiler: gcc
dist: trusty
dist: xenial

notifications:
email: false

addons:
apt:
sources:
- deadsnakes
packages:
- python3.7-dev

before_install:
# C++17
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq

install:
- pyenv global $(pyenv whence 2to3) # activate all python versions
- pip install pipenv

# C++17
- sudo apt-get install -qq g++-7 gcc-7
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 90
Expand All @@ -21,6 +32,15 @@ install:
- tar xf lcov_1.11.orig.tar.gz
- sudo make -C lcov-1.11/ install
- which lcov

# Install stockfish (used in search verification). Script from https://github.com/niklasf/python-chess/blob/master/.travis.yml
- wget https://stockfish.s3.amazonaws.com/stockfish-10-linux.zip
- unzip stockfish-10-linux.zip
- mkdir -p bin
- cp stockfish-10-linux/Linux/stockfish_10_x64_modern bin/stockfish
- chmod +x bin/stockfish
- export PATH="`pwd`/bin:${PATH}"
- which stockfish || (echo $PATH && false)

# Install coverals gem for uploading coverage to coveralls.
- gem install coveralls-lcov
Expand All @@ -30,18 +50,17 @@ before_script:
- gcov --version
- g++ --version
- PARENTDIR=$(pwd)
- mkdir $PARENTDIR/build && cd $PARENTDIR/build

script:
- pipenv install
- CMAKE_BUILD_TYPE=Coverage pipenv run python tests/test_search.py
- cd $PARENTDIR/build
- cmake -DCMAKE_BUILD_TYPE=Coverage $PARENTDIR
- make
- make gtest
- make bench
- make coverage
- printf "bench\nquit\n" | ./goldfish.x

after_success:
- cd $PARENTDIR/build
- lcov --list coverage_out.info.cleaned # Show test report in travis log.
- coveralls-lcov coverage_out.info.cleaned # uploads to coveralls
- bash <(curl -s https://codecov.io/bash) -f coverage_out.info.cleaned || echo "Codecov did not collect coverage reports"

7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
cmake_minimum_required(VERSION 3.0)

# Set project name here.
project(Goldfish VERSION 1.8.2 LANGUAGES CXX)
project(Goldfish VERSION 1.9.0 LANGUAGES CXX)

# Include stuff. No change needed.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
Expand All @@ -31,7 +31,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wfatal-errors")

# Build-type specific flags. Change as needed.
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Og")
SET(CMAKE_CXX_FLAGS_DEBUG "-g -O0")

message(STATUS "Building with the following extra flags: ${CMAKE_CXX_FLAGS}")

Expand Down Expand Up @@ -88,6 +88,9 @@ set(SOURCES
src/perft.cpp
src/position.cpp
src/search.cpp
src/searchmanagement.cpp
src/semaphore.cpp
src/timer.cpp
src/tt.cpp
)
set(TESTFILES
Expand Down
13 changes: 13 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
chester = "*"
python-chess = "*"

[requires]
python_version = "3.7"
37 changes: 37 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![Build Status](https://travis-ci.org/bsamseth/Goldfish.svg?branch=master)](https://travis-ci.org/bsamseth/Goldfish)
[![Coverage Status](https://coveralls.io/repos/github/bsamseth/Goldfish/badge.svg?branch=master)](https://coveralls.io/github/bsamseth/Goldfish?branch=master)
[![codecov](https://codecov.io/gh/bsamseth/Goldfish/branch/master/graph/badge.svg)](https://codecov.io/gh/bsamseth/Goldfish)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7f53976fd4bb42b4bfb2f53bd67fce65)](https://www.codacy.com/app/bsamseth/Goldfish?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=bsamseth/Goldfish&amp;utm_campaign=Badge_Grade)
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/bsamseth/Goldfish.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/bsamseth/Goldfish/context:cpp)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/bsamseth/Goldfish.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/bsamseth/Goldfish/context:python)
Expand Down Expand Up @@ -59,7 +60,7 @@ been added so far. The list is inspired in large part by [this writeup](http://w
- [X] Killer move heuristic
- [X] Principal variation search
- [X] Internal iterative deepening
- [X] Aspiration window search
- [X] Aspiration window search (repealed by PR #27, needs tuning before reapplying)
- [ ] Futility pruning
- [ ] Delta pruning in quiescence search.
+ [X] Prune when _no_ move can improve enough
Expand Down
2 changes: 1 addition & 1 deletion cmake/CodeCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
ADD_CUSTOM_TARGET(${_targetname}

# Cleanup lcov
${LCOV_PATH} --directory . --zerocounters
# ${LCOV_PATH} --directory . --zerocounters

# Run tests
COMMAND ${_testrunner} ${ARGV3}
Expand Down
2 changes: 1 addition & 1 deletion include/bound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace goldfish {

enum class Bound : uint8_t {
enum Bound : uint8_t {
NONE, LOWER, UPPER, EXACT = LOWER | UPPER
};

Expand Down
5 changes: 5 additions & 0 deletions include/position.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class Position {

bool is_attacked(Square target_square, Color attacker_color);

bool last_move_was_null_move();

private:
class Zobrist {
public:
Expand Down Expand Up @@ -109,6 +111,9 @@ class Position {
std::array<State, MAX_MOVES> states;
int states_size = 0;

std::array<Move, MAX_MOVES> moves;
int move_count = 0;

Zobrist &zobrist;

void clear_castling(Square square);
Expand Down
18 changes: 16 additions & 2 deletions include/search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,27 @@ class Search {

void update_search(int ply);

void save_pv(const Move move, const MoveVariation &src, MoveVariation &dest);

Value pv_search(Depth depth, Value alpha, Value beta, int ply, int move_number);

Value search_root(Depth depth, Value alpha, Value beta);

Value search(Depth depth, Value alpha, Value beta, int ply);

Value quiescent(Value alpha, Value beta, int ply);

void save_pv(Move move, MoveVariation &src, MoveVariation &dest);
};

inline uint64_t Search::get_total_nodes() {
return total_nodes;
}

inline void Search::save_pv(const Move move, const MoveVariation &src, MoveVariation &dest) {
dest.moves[0] = move;
for (int i = 0; i < src.size; i++) {
dest.moves[i + 1] = src.moves[i];
}
dest.size = src.size + 1;
}

}
18 changes: 18 additions & 0 deletions include/tt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,22 @@ void TranspositionTable<Mb_Size>::store(const uint64_t key, Value value, Bound b
tte->save(key, value, bound, depth, move);
}

// value_to_tt() adjusts a mate score from "plies to mate from the root" to
// "plies to mate from the current position". Non-mate scores are unchanged.
// The function is called before storing a value in the transposition table.
constexpr Value value_to_tt(Value v, int ply) {
assert(v != Value::NO_VALUE);
return v >= Value::CHECKMATE_THRESHOLD ? v + ply
: v <= Value::CHECKMATE_THRESHOLD ? v - ply : v;
}

// value_from_tt() is the inverse of value_to_tt(): It adjusts a mate score
// from the transposition table (which refers to the plies to mate/be mated
// from current position) to "plies to mate/be mated from the root".
constexpr Value value_from_tt(Value v, int ply) {
return v == Value::NO_VALUE ? Value::NO_VALUE
: v >= Value::CHECKMATE_THRESHOLD ? v - ply
: v <= Value::CHECKMATE_THRESHOLD ? v + ply : v;
}

}
Loading