Skip to content
Open
5 changes: 0 additions & 5 deletions .github/workflows/try_compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,10 @@ jobs:
- name: Configure CMake
shell: bash
run: |
CXX_FLAGS=""
LINK_FLAGS=""

cmake -B "${{ steps.vars.outputs.dir }}" \
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_CXX_FLAGS_DEBUG="$CXX_FLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$LINK_FLAGS" \
-S "${{ github.workspace }}"

- name: Build
Expand Down
23 changes: 20 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
cmake_minimum_required(VERSION 3.16)
# a chess library (bonus: you can integrate more piece types!) which
# supports Chess960 and is decently fast enough
# Copyright (C) 2025-2026 winapiadmin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
cmake_minimum_required(VERSION 3.14)
project(chesslib LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -51,7 +68,7 @@ if(BUILD_TESTING)
FetchContent_Declare(
doctest
GIT_REPOSITORY https://github.com/doctest/doctest.git
GIT_TAG v2.4.12
GIT_TAG v2.5.2
)
FetchContent_MakeAvailable(doctest)

Expand All @@ -76,4 +93,4 @@ if(BUILD_TESTING)
endif()
endif()

endif()
endif()
18 changes: 18 additions & 0 deletions attacks.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
a chess library (bonus: you can integrate more piece types!) which
supports Chess960 and is decently fast enough
Copyright (C) 2025-2026 winapiadmin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "attacks.h"

namespace chess::_chess {
Expand Down
54 changes: 53 additions & 1 deletion attacks.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
a chess library (bonus: you can integrate more piece types!) which
supports Chess960 and is decently fast enough
Copyright (C) 2025-2026 winapiadmin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once
#include "bitboard.h"
#include "fwd_decl.h"
Expand Down Expand Up @@ -126,7 +145,7 @@ struct Magic {
struct Magic {
Bitboard mask;
Bitboard magic;
int index;
size_t index;
Bitboard shift;
constexpr Bitboard operator()(Bitboard b) const { return (((b & mask)) * magic) >> shift; }
};
Expand Down Expand Up @@ -162,6 +181,39 @@ extern const std::array<Bitboard, 0x1480> BishopAttacks;
return (b & ~MASK_FILE[7]) << 1;
case Direction::SOUTH_EAST:
return (b & ~MASK_FILE[7]) >> 7;
case DOUBLE_NORTH:
return b << 16;

case DOUBLE_SOUTH:
return b >> 16;

case DOUBLE_EAST:
return (b & ~MASK_FILE[7] & ~(MASK_FILE[7] >> 1)) << 2;

case DOUBLE_WEST:
return (b & ~MASK_FILE[0] & ~(MASK_FILE[0] << 1)) >> 2;

case DOUBLE_NORTH_EAST: {
Bitboard t = (b & ~MASK_FILE[7]) << 9;
return (t & ~MASK_FILE[7]) << 9;
}

case DOUBLE_NORTH_WEST: {
Bitboard t = (b & ~MASK_FILE[0]) << 7;
return (t & ~MASK_FILE[0]) << 7;
}

case DOUBLE_SOUTH_EAST: {
Bitboard t = (b & ~MASK_FILE[7]) >> 7;
return (t & ~MASK_FILE[7]) >> 7;
}

case DOUBLE_SOUTH_WEST: {
Bitboard t = (b & ~MASK_FILE[0]) >> 9;
return (t & ~MASK_FILE[0]) >> 9;
}
case DIR_NONE:
return b;
default:
UNREACHABLE();
return 0;
Expand Down
18 changes: 18 additions & 0 deletions bitboard.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
a chess library (bonus: you can integrate more piece types!) which
supports Chess960 and is decently fast enough
Copyright (C) 2025-2026 winapiadmin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "types.h"

Expand Down
18 changes: 18 additions & 0 deletions chess960_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
a chess library (bonus: you can integrate more piece types!) which
supports Chess960 and is decently fast enough
Copyright (C) 2025-2026 winapiadmin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define DOCTEST_CONFIG_IMPLEMENT
#define DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
#include "moves_io.h"
Expand Down
18 changes: 18 additions & 0 deletions fwd_decl.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
a chess library (bonus: you can integrate more piece types!) which
supports Chess960 and is decently fast enough
Copyright (C) 2025-2026 winapiadmin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdint>
#include <type_traits>
Expand Down
24 changes: 24 additions & 0 deletions movegen.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
a chess library (bonus: you can integrate more piece types!) which
supports Chess960 and is decently fast enough
Copyright (C) 2025-2026 winapiadmin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// AVX512 and scalar bb-movegens

// License: https://github.com/official-stockfish/Stockfish/blob/master/COPYING.txt
// movegen references

// License: https://github.com/Disservin/chess-library/blob/master/LICENSE
#include "movegen.h"
#include "position.h"

Expand Down
18 changes: 18 additions & 0 deletions movegen.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
a chess library (bonus: you can integrate more piece types!) which
supports Chess960 and is decently fast enough
Copyright (C) 2025-2026 winapiadmin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "fwd_decl.h"
#include <array>
Expand Down
30 changes: 25 additions & 5 deletions moves_io.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
/*
a chess library (bonus: you can integrate more piece types!) which
supports Chess960 and is decently fast enough
Copyright (C) 2025-2026 winapiadmin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// UCI moves parsing

// License: https://github.com/Disservin/chess-library/blob/master/LICENSE
#include "moves_io.h"
#include "position.h"
#include "types.h"
#include <algorithm>
#include <iostream>
#include <regex>
#include <string_view>
#if defined(__EXCEPTIONS)
#define THROW_IF_EXCEPTIONS_ON(stuff) throw stuff
Expand Down Expand Up @@ -237,13 +256,14 @@ template <typename T, typename P> Move parseSan(const _Position<T, P> &pos, std:
// consume it
std::string src_sq_str = prefix.substr(prefix.size() - 2, 2);
src_square = parse_square(src_sq_str);
if (src_square == SQ_NONE)
if (src_square == SQ_NONE) {
THROW_IF_EXCEPTIONS_ON(IllegalMoveException("illegal san: '" + _san + "' in " + pos.fen()));
return Move::none();
}
prefix.resize(prefix.size() - 2);
has_src_square = true;
}
}

has_src_square = src_square != SQ_NONE;
// 7) Detect piece letter at front if present
PieceType piece_type = NO_PIECE_TYPE;
if (!prefix.empty()) {
Expand Down
18 changes: 18 additions & 0 deletions moves_io.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
a chess library (bonus: you can integrate more piece types!) which
supports Chess960 and is decently fast enough
Copyright (C) 2025-2026 winapiadmin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "fwd_decl.h"
#include <cstdint>
Expand Down
31 changes: 25 additions & 6 deletions non_core_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
a chess library (bonus: you can integrate more piece types!) which
supports Chess960 and is decently fast enough
Copyright (C) 2025-2026 winapiadmin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define DOCTEST_CONFIG_IMPLEMENT
#ifndef __EXCEPTIONS
#define DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS
Expand Down Expand Up @@ -418,11 +436,11 @@ TEST_SUITE("SAN Parser") {
auto b = Position{ "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQK2R w KQkq - 0 17" };

Move m = Move::make<Move::CASTLING>(Square::SQ_E1, Square::SQ_H1);
#if defined(_DEBUG) && !defined(NDEBUG)
REQUIRE_THROWS_WITH_AS(uci::parseSan(b, "0-0+?!"),
Move m2 = Move::none();
REQUIRE_THROWS_WITH_AS(m2 = uci::parseSan(b, "0-0+?!"),
"illegal san: '0-0+?!' in rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQK2R w KQkq - 0 17",
chess::uci::IllegalMoveException);
#endif
REQUIRE(m2 == Move::none());
REQUIRE(uci::parseSan(b, "0-0+?!", true) == m);
}

Expand All @@ -431,11 +449,12 @@ TEST_SUITE("SAN Parser") {

Move m = Move::make<Move::CASTLING>(Square::SQ_E1, Square::SQ_A1);

#if defined(_DEBUG) && !defined(NDEBUG)
REQUIRE_THROWS_WITH_AS(uci::parseSan(b, "0-0-0+?!"),
Move m2 = Move::none();
REQUIRE_THROWS_WITH_AS(m2 = uci::parseSan(b, "0-0-0+?!"),
"illegal san: '0-0-0+?!' in rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/R3K2R w KQkq - 0 1",
chess::uci::IllegalMoveException);
#endif
REQUIRE(m2 == Move::none());

REQUIRE(uci::parseSan(b, "0-0-0+?!", true) == m);
}

Expand Down
Loading
Loading