GithubHelp home page GithubHelp logo

rhalbersma / dctl Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 0.0 7.38 MB

Draughts and checkers template library

License: Boost Software License 1.0

CMake 1.67% C++ 98.33%
header-only draughts checkers template-library game-library

dctl's Introduction

DCTL: Draughts and Checkers Template Library

Language Standard License Lines of Code

C++ template library for the games of draughts and checkers, supporting almost all known rules variations, board sizes and game objectives.

Disclaimer

This library is currently in a pre-alpha stage. All code is subject to change without prior notice.

Introduction

Draughts is a family of related board games played in many regions across the world:

  • There are many country-specific game rules such as International/Brazilian/Canadian, American/English, Russian, Italian, Spanish/Portugese, Czech, Thai, and Frisian draughts.
  • Draughts is played on checkered boards of dimensions 8x8, 10x10 and 12x12.
  • The common game objective is "the first player to have no moves left, loses". A less common variation is so-called misère play ("first to have no moves left, wins"), also known as "suicide", "giveaway", or "qui-perd-gagné".

Many draughts variants have an official governing body, such as the Fédération Mondiale du Jeu de Dames (FMJD, World Draughts Federation).

Scope

The DCTL supports all above mentioned draughts variants with official rules, on all board sizes up to 18x18. Most existing draughts variants have a high percentage of draws when played between experienced players. Historically, many small tweaks to the game rules have been proposed. Even former world champions such as Herman Hoogland proposed new variants. The DCTL supports some of these variants. In particular, the recently proposed Killer Draughts is actively supported.

Usage

The DCTL provides a series of C++ templates to define the board geometry and game rules of draughts variants. With these templates, one can read and write draughts positions from so-called FEN strings using Portable Draughts Notation. Once a position variable has been initialized with such a FEN string, the DCTL provides further templates to analyze them using a search algorithm, which is supported by a typical board game engine infrastructure of e.g. a move generator, evaluation function and hash table.

Tip

Consult the test-suite sources (under the dctl/test directory) for concrete usage examples.

Road-map

The DCTL does not yet provide a fully functioning game engine that can be plugged into a GUI. It is currently not possible to play a game against a program based on the DCTL. Functionality being planned includes:

Requirements

These header-only libraries depend on the C++ Standard Library and Boost and are continuously being tested with the following conforming conforming C++20 compilers:

Platform Compiler Versions Build
Linux GCC 11, 12, 13-SVN CI currently being ported to GitHub Actions
Linux Clang 16-SVN CI currently being ported to GitHub Actions

Installation

Download

Clone the dctl and the bit_set, tabula and xstd repositories as dependencies to a directory of your choice:

  cd ~/projects/
  git clone https://github.com/rhalbersma/dctl.git
  git clone https://github.com/rhalbersma/bit_set.git
  git clone https://github.com/rhalbersma/tabula.git
  git clone https://github.com/rhalbersma/xstd.git

Test-suite

To make sure that your build environment is compatible with the DCTL requirements, the DCTL comes with an extensive suite of unit tests, placed in the dctl/test sub-directory. To build and run the test-suite, follow the requirements (in particular: compile Boost.Test), and type (where -j N builds on N cores in parallel)

  cd dctl
  mkdir build && cd build
  cmake ..
  cmake --build . -j N
  ctest -E "search|traversal"

The build will take less than a minute on a 3.5 GHz Intel i7 (and longer for systems with less parallelism). The test-suite itself takes a second to run. Note that the ctest command excludes all unit tests that do a tree search or traversal (these tests will take several minutes to hours to run, respectively). If you do not see any errors, the tests succeeded. Congratulations: your system supports the DCTL, and you are now ready to start coding!

Contribute

Any feature requests, ideas and contributions are much appreciated! The recommended way to contribute code is through GitHub pull requests.

Acknowledgments

Special thanks to Aart Bik, Ed Gilbert, Fabien Letouzey, Walter Thoen and Wieger Wesselink for encouragement, testing, and exchange of ideas.

License

Copyright Rein Halbersma 2010-2023. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

dctl's People

Contributors

rhalbersma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dctl's Issues

DCTL failed with error C2679 when build by msvc on Windows

DCTL failed with error C2679 when build by msvc on Windows, I use latest version 2ee0699 on master branch. Could you please help take a look at this? Noted that this issue only found when compiles with unreleased vctoolset, that next release of MSVC will have this behavior.

You can repro this issue as the steps below:

  1. git clone https://github.com/rhalbersma/dctl.git D:\DCTL\src
  2. git clone https://github.com/rhalbersma/xstd.git D:\DCTL\xstd
  3. git clone https://github.com/rhalbersma/int_set.git D:\DCTL\int_set
  4. extract boost_1_67_0.zip to D:\DCTL\boost_1_67_0\x64
  5. open a VS 2017 amd64 command prompt as admin and browse to D:\DCTL
  6. cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_SYSTEM_VERSION=10.0.17134.0 -DBOOST_ROOT=D:\DCTL\boost_1_67_0\x64\boost -DBOOST_INCLUDEDIR=D:\DCTL\boost_1_67_0\x64 ..\src\
  7. msbuild /m /p:Configuration=Release;Platform=x64 dctl.sln /t:Rebuild

Our workaround:
database.hpp:
std::copy(m_files.begin(), m_files.end(), std::ostream_iteratorstd::string(std::cout, "\n"));
=>
std::copy(m_files.begin(), m_files.end(), std::ostream_iterator<std::wstring, wchar_t>(std::wcout, L"\n"));

Error info:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\include\xutility(1784): error C2679: binary '=': no operator found which takes a right-hand operand of type 'std::filesystem::path' (or there is no acceptable conversion)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\include\iterator(232): note: could be 'std::ostream_iterator<std::string,char,std::char_traits> &std::ostream_iterator<std::string,char,std::char_traits>::operator =(std::ostream_iterator<std::string,char,std::char_traits> &&)'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\include\iterator(232): note: or 'std::ostream_iterator<std::string,char,std::char_traits> &std::ostream_iterator<std::string,char,std::char_traits>::operator =(const std::ostream_iterator<std::string,char,std::char_traits> &)'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\include\iterator(208): note: or 'std::ostream_iterator<std::string,char,std::char_traits> &std::ostream_iterator<std::string,char,std::char_traits>::operator =(const _Ty &)'
with
[
_Ty=std::string
]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\include\xutility(1784): note: while trying to match the argument list '(std::ostream_iterator<std::string,char,std::char_traits>, std::filesystem::path)'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\include\xutility(1821): note: see reference to function template instantiation '_OutIt std::_Copy_uncheckedstd::filesystem::path*,_Iter(_InIt,_InIt,_OutIt)' being compiled
with
[
_OutIt=std::ostream_iterator<std::string,char,std::char_traits>,
_Iter=std::ostream_iterator<std::string,char,std::char_traits>,
_InIt=std::filesystem::path *
]
D:\DCTL\src\include\dctl\egdb\database.hpp(53): note: see reference to function template instantiation '_OutIt std::copy<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,std::ostream_iterator<std::string,char,std::char_traits>>(_InIt,_InIt,_OutIt)' being compiled
with
[
_OutIt=std::ostream_iterator<std::string,char,std::char_traits>,
_Ty=std::filesystem::path,
_InIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_typesstd::filesystem::path>>
]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\include\filesystem(2066): note: see reference to class template instantiation 'std::chrono::time_pointstd::filesystem::_File_time_clock,std::filesystem::_File_time_clock::duration' being compiled
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\include\xstring(1689): note: see reference to class template instantiation 'std::basic_string_view<wchar_t,std::char_traits<wchar_t>>' being compiled

DCTL failed to run egdb.database test on release and debug configuration with MSVC on Windows

DCTL failed to run egdb.database test on release and debug configuration with MSVC on Windows. It can be reproduced on master branch latest reversion a63d2a3. Could you help take a look at this? Thanks a lot.

Repro steps:

  1. git clone https://github.com/rhalbersma/dctl.git D:\DCTL\src
  2. open a VS 2017 amd64 command prompt as admin and browse to D:\DCTL
  3. git clone https://github.com/rhalbersma/xstd.git D:\DCTL\xstd
  4. git clone https://github.com/rhalbersma/bit_set.git D:\DCTL\bit_set
  5. put boost_1_69_0 under C:\boost_1_69_0\x64
  6. cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_SYSTEM_VERSION=10.0.17134.0 -DBOOST_ROOT=C:\boost_1_69_0\x64\boost -DBOOST_INCLUDEDIR=C:\boost_1_69_0\x64 ..\src\
  7. msbuild /m /p:Configuration=Release;Platform=x64 dctl.sln /t:Rebuild
  8. ctest --build-config Release -E "egdb.divide|search|traversal"

log_x64_test.log

Failures:
Start 35: egdb.database
35/37 Test #35: egdb.database ........................Exit code 0xc0000135
***Exception: 0.05 sec
Start 36: egdb.index
36/37 Test #36: egdb.index ........................... Passed 0.34 sec
Start 37: util.literals
37/37 Test #37: util.literals ........................ Passed 0.05 sec

97% tests passed, 1 tests failed out of 37

Total Test time (real) = 2.87 sec

The following tests FAILED:
35 - egdb.database (Exit code 0xc0000135
)

Investigate per-piece vs per-direction processing

  • For densely packed pieces, it is likely cheaper to do per-direction filtering, and then per-piece processing.
  • For sparsely packed pieces, it is likely cheaper to do per-piece processing over all directions simultaneously.

A good proxy for sparsity might be the number of empty squares minus 4 times (or another small power of 2) the number of pieces:

  • if this is negative, the pieces are dense (say 40 pawns on a 10x10 board, 50 - (4 + 1) * 40 = -150).

  • if this is non-negative, the pieces are sparse (say 10 kings on a 10x10 board: 50 - (4 + 1) * 10 = 0).

  • Since the initial position starts with densely packed men, the default for pawns should be per-direction filtering followed by per-piece processing.

  • In endgames, pieces are mostly sparsely packed, the default for kings should therefore be per-piece processing over all directions simultaneously.

The question is whether we should dynamically check for sparsity for pawns and kings. In pathological positions (40 kings e.g.) we get a massive slow-down. If __builtin_expect is cheap enough, it might be worthwhile to test for this. Note that we currently already check for pieces(/*piece type*/).empty(). Instead, we might now branch on pieces(/*piece type*/).count().

Note that for long-ranged king moves, per-direction filtering should be followed by per-piece lookups on the remaining empty squares ahead. This is what Moby Dam implements unconditionally.

DCTL failed with error C2988 C2059 C2334 when built by msvc on Windows

DCTL failed with C2988 C2059 C2334 when built by msvc on Windows, I use source db7db34 on master branch. Could you help take a look at this? Noted that this issue only found when compiles with unreleased vctoolset, that next release of MSVC will have this behavior.

Repro steps:

  1. git clone https://github.com/rhalbersma/dctl.git D:\DCTL\src
  2. open a VS 2017 amd64 command prompt as admin and browse to D:\DCTL
  3. git clone https://github.com/rhalbersma/xstd.git D:\DCTL\xstd
  4. git clone https://github.com/rhalbersma/bit_set.git D:\DCTL\bit_set
  5. put boost_1_67_0 under C:\boost_1_67_0\x64
  6. cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_SYSTEM_VERSION=10.0.17134.0 -DBOOST_ROOT=C:\boost_1_67_0\x64\boost -DBOOST_INCLUDEDIR=C:\boost_1_67_0\x64 ..\src\
  7. msbuild /m /p:Configuration=Release;Platform=x64 dctl.sln /t:Rebuild

Failures:
D:\DCTL\src\include\dctl\core\board\basic_board.hpp(142,1): error C2988: unrecognizable template declaration/definition
XSTD_PP_CONSTEXPR_INTRINSIC static auto squares_filter(UnaryPredicate pred) noexcept
^
D:\DCTL\src\include\dctl\core\board\basic_board.hpp(301): note: see reference to class template instantiation 'dctl::core::block_adl::basic_board' being compiled
};
D:\DCTL\src\include\dctl\core\board\basic_board.hpp(142,1): error C2059: syntax error: 'constant'
XSTD_PP_CONSTEXPR_INTRINSIC static auto squares_filter(UnaryPredicate pred) noexcept
^
D:\DCTL\src\include\dctl\core\board\basic_board.hpp(143,1): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
{
^

Add support for Tanzanian rule

Do not forget to add Tanzanian rule (American checkers but with flying king) we will appreciate. It is only available in few apps, but most famous one is Dalmax checkers for Android.

Investigate code coverage

  • put code inside if constexp on separate line
  • eliminate old fill-based move detection/generation
  • eliminate code that was put there for completeness (YAGNI)

complete Frisian draughts

We are currently lacking data members in the state class to track the most recently moved kings.

  • define data structure tracking the most recently moved kings
  • modify operator<< to print out the number of moves for the most recently moved kings

use [[no_unique_address]]

This allows better layout of basic_action and basic_state and automatic generation of operator== for these classes.

Note that this is not yet supported for Visual C++.

DCTL build fails on MSVC with error C2280, error C2088, error C3889...

Hi all,
DCTL failed to build with "error C2280, error C2088, error C3889..."with MSVC on Windows. Could you please help look at this issue?

Environment:
Windows: windows server 2019
VS: 2019

Repro steps:
1.open VS2019 x64 tools command
2.git clone https://github.com/rhalbersma/dctl F:\gitP\rhalbersma\dctl
3.cd F:\gitP\rhalbersma\dctl
4.mkdir build_amd64 & cd F:\gitP\rhalbersma\dctl\build_amd64
5.set VSCMD_SKIP_SENDTELEMETRY=1 & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -host_arch=amd64 -arch=amd64
6.msbuild /m /p:Platform=x64 /p:Configuration=Release dctl.sln /t:Rebuild

Error info:
F:\gitP\rhalbersma\dctl\include\dctl/core/model/detail/builder.hpp(221,86): error C2280: 'bool dctl::core::basic_action<dctl::core::block_adl::international,dctl::core::block_adl::basic_boarddctl::core::block_adl::international>::operator ==(const dctl::core::basic_action<dctl::core::block_adl::international,dctl::core::block_adl::basic_boarddctl::core::block_adl::international> &) const': attempting to reference a deleted function [F:\gitP\rhalbersma\dctl\build_amd64\example\play.vcxproj]
F:\gitP\rhalbersma\dctl\include\dctl/core/model/detail/builder.hpp(221,86): error C2088: '==': illegal for class [F:\gitP\rhalbersma\dctl\build_amd64\example\play.vcxproj]
F:\gitP\rhalbersma\dctl\include\dctl/core/model/detail/builder.hpp(221,37): error C3889: call to object of class type 'std::ranges::_None_of_fn': no matching call operator found [F:\gitP\rhalbersma\dctl\build_amd64\example\play.vcxproj]
F:\gitP\rhalbersma\dctl\include\dctl/core/model/detail/builder.hpp(204,55): error C2297: '||': not valid as right operand has type 'void' [F:\gitP\rhalbersma\dctl\build_amd64\example\play.vcxproj]
F:\tools\boost_1_70_0\x64\boost/graph/topological_sort.hpp(44,1): error C2220: the following warning is treated as an error [F:\gitP\rhalbersma\dctl\build_amd64\test\egdb.divide.vcxproj]

log
build.log

Investigate long range king jump capture

  • landing after final jump
  • intermediate sliding and turning
  • add 2-argument jump_sources for short-ranged pieces
  • store number of sliding squares ahead into builder

Generalize action building

  • store visited squares and jump order (suitable for GUIs that do jump path animation)
  • counting container (incrementing a counter, rather than building an action) when keeping duplicates
    • for trivial jump precedence
    • for non-trivial jump precedence
  • successor container (building the successor state, rather than an action)
  • make an action_view (inspired by std::string_view) that can adopt either
    • an action
    • a state and an action
    • two states
  • action_view should support
    • jump precedence comparisons
    • make on states
    • undo on states

Explore design space of endgame database building

  • Binomial coefficients
    • ranking/unranking of combinations (colex)
    • ranking/unranking of positions
    • increment/decrement of combinations (colex)
    • increment/decrement of positions
    • gappless position indexing
    • symmetry reduced indexing
  • Subdivisions
    • by piece counts
    • by piece counts, leading ranks (any region)
    • by piece counts, leading ranks, leading rank configurations
    • by piece counts, leading ranks, leading rank configurations, subleading ranks
  • Conversions
    • enumerate capture conversions
    • enumerate promotion conversions
    • enumerate leading rank conversions
    • enumerate subleading rank conversions
  • Build dependencies
    • create Boost.Graph (vertices = subdivisions, edges = conversions)
    • topological sort for valid build order
    • total work
    • minimal memory requirements
    • uniform-cost search for critical path
    • potential parallelism
    • bread-first search for parallel build order
  • Build algorithm
    • forward iteration
    • backward iteration
    • outcounting
    • leapfrog
    • one-sided vs. two-sided
  • Metric
    • bitbases (won, not won)
    • WLD (win, loss, draw)
    • DTZ (distance to zeroing move)
    • DTM (distance to mate)
  • Statistics
    • disk I/O
    • memory access
    • moves generated
    • moves done/undone
    • ranking/unranking
    • estimate performance model (per build algorithm)
    • automate build algorithm selection per subdivision
  • Storage
    • design format of db, idx, log, stats files
    • serialization of std::vector, boost::dynamic_bitset
    • explore iostreams performance settings
  • Compression
    • run-length
    • Tunstall
    • explore Re-Pair
  • Access
    • LRU cache
    • explore memory mapped I/O

remove board::mask namespace

The various variable templates should live in the dctl namespace, similar to the rule traits.

  • make variable templates for the various mask classes
  • move the variable templates into board_traits.hpp

update readme.md

  • GitHub instead of BitBucket
  • latest versions of clang, libstdc++, Boost

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.