Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3a23ad6
added generate hash key
HCaraca Aug 3, 2022
409e4ec
hash key update and tests
HCaraca Aug 5, 2022
c501452
Merge branch 'develop' into transposition-tables
jsilll Aug 8, 2022
0a77fe7
zobrist out of movegen and perft tests
HCaraca Aug 9, 2022
0db850f
Merge branch 'transposition-tables' of github.com:jsilll/chess-engine…
HCaraca Aug 9, 2022
5a7e58d
zobrist in engine
HCaraca Aug 10, 2022
7a91347
bug fixed
HCaraca Aug 10, 2022
2c8b483
small cleanups
jsilll Aug 13, 2022
e9cb66e
fixed refactoring errors
jsilll Aug 13, 2022
edfb992
fixed stack overflow bug and removed debug checks from perft
jsilll Aug 13, 2022
a6c4702
only one movepicker instatiated now
jsilll Aug 13, 2022
80c466b
removed constructor from ttable
jsilll Aug 14, 2022
fe42084
get_pv typo
jsilll Aug 14, 2022
c6523c7
fixed mate representation when losing
jsilll Aug 14, 2022
b3c957a
small refactor
jsilll Aug 15, 2022
73d28d8
added list of moves to tt (not sure if correct)
HCaraca Aug 19, 2022
3a72b77
Minor Fixes
jsilll Aug 21, 2022
b4a0867
small variable refactor
jsilll Aug 21, 2022
755f737
small fix on only one legal move edge case
jsilll Aug 22, 2022
8db9216
small tweaks
jsilll Aug 22, 2022
e146cc9
added repetition detection
jsilll Aug 23, 2022
370669f
Merge branch 'develop' into transposition-table
jsilll Aug 23, 2022
8a00868
Update README.md
jsilll Aug 23, 2022
ae86a46
time control budget calculation adjustments
jsilll Aug 23, 2022
ac9e7bd
Merge branch 'transposition-table' of github.com:jsilll/chess-engine …
jsilll Aug 23, 2022
17e218e
improved types and moved big tables to the heap
jsilll Aug 24, 2022
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(chess_engine VERSION 1.0 DESCRIPTION "Chess Engine")

set(CMAKE_CXX_FLAGS "-Wall -Wpedantic -Wextra -Wconversion -Werror")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_DEBUG "-g")

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Features
- [Null Move Pruning](https://www.chessprogramming.org/Null_Move_Pruning)
- [Null Window Search](https://www.chessprogramming.org/Null_Window)
- [Transposition Table](https://en.wikipedia.org/wiki/Transposition_table)
- [Repetition Detection](https://www.chessprogramming.org/Repetitions)

Building and Installation
===
Expand Down
22 changes: 12 additions & 10 deletions src/engine/bitboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ namespace bitboard
return (int)count;
}

int bit_scan(u64 bb)
Square bit_scan(u64 bb)
{
if (bb)
{
return bit_count((bb & -bb) - 1);
return (Square)bit_count((bb & -bb) - 1);
}
return -1;

return EMPTY_SQUARE;
}

int bit_scan_forward(u64 bb)
Square bit_scan_forward(u64 bb)
{
static const int index64[64] = {
0, 47, 1, 56, 48, 27, 2, 60,
Expand All @@ -41,32 +42,33 @@ namespace bitboard
13, 18, 8, 12, 7, 6, 5, 63};

static const u64 debruijn64 = 0x03f79d71b4cb0a89;
return index64[((bb ^ (bb - 1)) * debruijn64) >> 58];
return (Square)index64[((bb ^ (bb - 1)) * debruijn64) >> 58];
}

u64 set_occupancy(int index, int bits_in_mask, u64 attack_mask)
{
u64 occupancy = ZERO;
for (int bit = 0; bit < bits_in_mask; bit++)
{
int lsb_sq = bit_scan_forward(attack_mask);
Square lsb_sq = bit_scan_forward(attack_mask);
pop_bit(attack_mask, lsb_sq);
if (index & (1 << bit))
{
occupancy |= tables::SQUARE_BB[lsb_sq];
occupancy |= tables::square_to_bitboard((Square)lsb_sq);
}
}

return occupancy;
}

void print(u64 bb)
{
for (int i = 7; i >= 0; i--)
for (int i = RANK_8; i >= RANK_1; i--)
{
std::cout << i + 1 << " ";
for (int n = 0; n < 8; n++)
for (int n = FILE_A; n < N_FILES; n++)
{
std::cout << ((bb >> utils::get_square(i, n)) & ONE) << " ";
std::cout << ((bb >> utils::get_square((Rank)i, (File)n)) & ONE) << " ";
}
std::cout << "\n";
}
Expand Down
18 changes: 13 additions & 5 deletions src/engine/bitboard.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#pragma once

#include <cstdint>

#include <engine/constants.hpp>

typedef std::uint64_t u64;

constexpr u64 ONE = 1ULL;
constexpr u64 ZERO = 0ULL;

namespace bitboard
{

// Common Bitboard Operations
inline bool get_bit(u64 bb, int sq) { return ((bb >> sq) & 1ULL); }
inline void pop_bit(u64 &bn, int sq) { bn &= ~(1ULL << sq); }
inline bool get_bit(u64 bb, Square sq) { return ((bb >> sq) & 1ULL); }
inline void pop_bit(u64 &bn, Square sq) { bn &= ~(1ULL << sq); }
inline void pop_last_bit(u64 &bb) { bb &= bb - 1; }
inline void set_bit(u64 &bb, int sq) { bb |= (1ULL << sq); }
inline void set_bit(u64 &bb, Square sq) { bb |= (1ULL << sq); }

// Common Bitboard Shifts
inline u64 sout_one(u64 bb) { return (bb >> 8); }
Expand All @@ -34,15 +42,15 @@ namespace bitboard
* @param bb
* @return unsigned int
*/
int bit_scan(u64 bb);
Square bit_scan(u64 bb);

/**
* @brief Returns index of LSB bit
*
* @param bb
* @return unsigned int
*/
int bit_scan_forward(u64 bb);
Square bit_scan_forward(u64 bb);

/**
* @brief Sets the occupancy bits
Expand Down
Loading