Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add files via upload
  • Loading branch information
justNo4b committed Aug 31, 2020
1 parent 1e264da commit df886b1
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 15 deletions.
21 changes: 21 additions & 0 deletions Doxyfile
@@ -0,0 +1,21 @@
PROJECT_NAME = "Drofa"
PROJECT_BRIEF = "UCI Chess Engine"
PROJECT_NUMBER = 1.0.0

INPUT = src README.md

EXTRACT_PRIVATE = YES
EXTRACT_STATIC = YES

OUTPUT_DIRECTORY = doc

GENERATE_LATEX = NO

USE_MDFILE_AS_MAINPAGE = README.md
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
SEARCHENGINE = YES
DISABLE_INDEX = YES
GENERATE_TREEVIEW = YES
HTML_DYNAMIC_SECTIONS = YES
HTML_TIMESTAMP = YES
89 changes: 89 additions & 0 deletions Drofa_changelog
@@ -0,0 +1,89 @@
Drofa changelog (initial Shallow_Blue commit -> Drofa 1.0)

1. Fuxed 50-move detection bug
2. Fixed KillerMove bug causing to have 2 exact killers sometimes
3. Fixed History updating in the beta cutoff area

-------------> tested movetime decreased for same positions across 1 game.
4. Implemented NULL move pruning
-------------> proved depth gain, elo gain not tested
5. Refactored evaluation
a. PSQT - King
b. PSQT - Rook
c. All PSQT and mobility tweaked
6. Fixed RookOnOpen bug
7. Added RookOnSemiOpen evaluation

--------------> proven elo gain
+50,7 +-43; 200 game test (+93; -64; =43) with disabled kingshield.
TC 30`` + 1``
------------------------------------------------------------------

8._kingPawnShield replaced with KingSafety function.
--------------> no proved elo gain for either of them.
Rank Name Elo +/- Games Score Draws
0 Drofa_newSafety 9 29 400 51.2% 25.5%
1 Drofa_PSQT_rescaled -9 42 200 48.8% 23.5%
2 Drofa_old_Safety -9 41 200 48.8% 27.5%

-------------> for now testing with king safety disabled.
----------------------------------------------------------------
9. IsItDeadDraw function implemented
-------------> no elo gain in 200-games test (but almost 0 expected i guess)

10. Full rework of the HASH_Table.
a) Now allocating memory ~32MB default now
b) Persistent throught moves

---------------------------> big elo gain (200 games test)
Score of Drofa_HT_test(32MB) vs Drofa_DD_noSafety: 98 - 61 - 41 [0.593]
Elo difference: 65.02 +/- 43.68
----------------------------------------------------------------
Bug with 0.00 score is seriously affecting gameplay.
The bigger HASH - more frequent bug.

11. HashTable Bug fixed. Minor _nodes counting bug fixed. 256 MB has default now.
--------------------------------->test vs old HASH (32MB, buggy)
Score of Drofa_bugFIX vs Drofa_HT_test: 80 - 61 - 59 [0.547]
Elo difference: 33.11 +/- 40.67

200 of 200 games finished.

Although it is not clear weather it is hash size or no bugs working.

12. Some search Sped UPs. Together ~1.8kk nps vs 0.7kk nps in startpos
~+90 elo gain (+80 -30 = 90) in 200 games test. Approx, computer crush

40 games match vs Vice:

Score of Drofa__ vs vice: 12 - 17 - 11 [0.438]
Elo difference: -43.66 +/- 94.35

13. More speed ups. ~2.2kk nps in startpos. Fixed bug that slowed engine down
the longer game lasts. Fixed bug that caused crush under high search depth.

14. Probe hashentry in _root. Nodes++ now in the root too.
+0 elo over ~300 games test

15. Probe hashentry in _root removed (caused bug with repetition detection).

16. King Safety reactivated. Most Likely elogainer:
---------------------------------------------------
400 game test:
+26 +/-29 elo
---------------------------------------------------
17. Pawn hashtable was rewritten to be structured as regular hashtable.
Now 250 MB hash and 6 MB pawn hash.
This also fixed memory leaking.
Elo gain/loss not tested.

18. Drofa 1.0 release.
Final stability test before release: 500 games vs VICE 60s + 1s:
----------------------------------------------------------------
Score of Drofa( vs vice: 212 - 147 - 141 [0.565]
Elo difference: 45.42 +/- 25.95

500 of 500 games finished.

0 crushes, 0 mem leaks.
---------------------------------------------------------------
28 changes: 13 additions & 15 deletions LICENSE
@@ -1,21 +1,19 @@
MIT License
Copyright (c) 2017-2019 Rhys Rustad-Elliott
CopyRight (c) 2020 Litov Alexander

Copyright (c) 2020 justNo4b

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 changes: 52 additions & 0 deletions Makefile
@@ -0,0 +1,52 @@
CXX ?= g++

SRC_DIR = $(shell pwd)/src

CPP_FILES = $(wildcard src/*.cc)
TEST_CPP_FILES = $(filter-out src/main.cc, $(sort $(CPP_FILES) $(wildcard test/*.cc)))

OBJ_FILES = $(addprefix obj/,$(notdir $(CPP_FILES:.cc=.o)))
TEST_OBJ_FILES = $(addprefix obj/,$(notdir $(TEST_CPP_FILES:.cc=.o)))

LD_FLAGS ?= -pthread -flto
CC_FLAGS ?= -Wall -std=c++11 -O3 -march=native -flto -pthread -fno-exceptions

# Catch makes use of C++ exceptions, so remove -fno-exceptions when making a test build
test: CC_FLAGS = -Wall -std=c++11 -O3 -march=native -flto -pthread

# Debug compile and linker flags (remove optimizations and add debugging symbols)
debug debug-test: CC_FLAGS = -Wall -std=c++11 -g -D__DEBUG__
debug debug-test: LD_FLAGS = -pthread

OBJ_DIR = obj

BIN_NAME = Drofa
TEST_BIN_NAME = DrofaTest

all: $(OBJ_DIR) $(BIN_NAME)

debug: all

debug-test: $(OBJ_DIR) $(TEST_BIN_NAME)

test: $(OBJ_DIR) $(TEST_BIN_NAME)

$(BIN_NAME): $(OBJ_FILES)
$(CXX) $(LD_FLAGS) -o $@ $^

$(TEST_BIN_NAME): $(TEST_OBJ_FILES)
$(CXX) $(LD_FLAGS) -o $@ $^

obj/%.o: src/%.cc
$(CXX) $(CC_FLAGS) -c -o $@ $<

obj/%.o: test/%.cc
$(CXX) $(CC_FLAGS) -I $(SRC_DIR) -c -o $@ $<

$(OBJ_DIR):
mkdir $(OBJ_DIR)

clean:
rm -rf $(OBJ_DIR)
rm -f $(TEST_BIN_NAME)
rm -f $(BIN_NAME)
126 changes: 126 additions & 0 deletions README.md
@@ -0,0 +1,126 @@
<h1 align="center">Drofa</h1>

A UCI chess engine written in C++11.

## Origins
Drofa started as fork of the <a href="https://github.com/GunshipPenguin/shallow-blue">Shallow Blue</a> chess engine.
My initial intention was to take weak, but stable and working chess engine and try to improve it,
learning c++ along the way.

The base-goal is to reach strenght of play comparable to the <a href="https://github.com/peterwankman/vice">VICE</a> chess engine.
The mid-goal - get to ~2500 rating on the CCRL
Far goal (probably will never be reached) - get into top 100 of the CCRL.

## Chages from Shallow Blue
For now Drofa can be considered as highly advanced fork of the Shallow Blue, with 2 features
being completely rewritten by me: hashtable and pawn hashtable.

Evaluation function was refactored with an elo-gain in self-play, although its still reqire much
work, because for now tapered eval in fact is used much less than in original Shallow Blue, which is a shame.

Some features were added during the work:
- QSearch move generator (althought i think current implementation is lazy and it can be done better)
- Null-move pruning
- Delta pruning (again, very lazy implementation)
- Various bugfixes

But most of the elo-gainers was some code restructuring and optimizations.
It allowed Drofa to be ~8x times faster than Shallow Blue.

Almost-full changelog with elo-gains measured for some of the features
can be found in the `Drofa_changelog` file.

## Features

- Board representation
- [Bitboards](https://en.wikipedia.org/wiki/Bitboard)
- Move generation
- [Magic bitboard hashing](https://www.chessprogramming.org/Magic_Bitboards)
- Search
- [Principal variation search](https://www.chessprogramming.org/Principal_Variation_Search)
- [Iterative deepening](https://en.wikipedia.org/wiki/Iterative_deepening_depth-first_search)
- [Quiescence search](https://en.wikipedia.org/wiki/Quiescence_search)
- [Check extensions](https://www.chessprogramming.org/Check_Extensions)
- [Transposition table](https://en.wikipedia.org/wiki/Transposition_table)
- Search Pruning and Reductions
- [Null move pruning](https://www.chessprogramming.org/Null_Move_Pruning)
- [Delta pruning](https://www.chessprogramming.org/Delta_Pruning)
- Evaluation
- [Piece square tables](https://www.chessprogramming.org/Piece-Square_Tables)
- [Pawn structure](https://www.chessprogramming.org/Pawn_Structure)
- [King safety](https://www.chessprogramming.org/King_Safety)
- [Bishop pairs](https://www.chessprogramming.org/Bishop_Pair)
- [Rooks on open/halfopen files](https://www.chessprogramming.org/Rook_on_Open_File)
- [Mobility](https://www.chessprogramming.org/Mobility)
- [Evaluation tapering](https://www.chessprogramming.org/Tapered_Eval)
- [Pawn HashTable]
- Move ordering
- [Hash move](https://www.chessprogramming.org/Hash_Move)
- [MVV/LVA](https://www.chessprogramming.org/MVV-LVA)
- [Killer heuristic](https://www.chessprogramming.org/Killer_Heuristic)
- [History heuristic](https://www.chessprogramming.org/History_Heuristic)
- Other
- [Opening book support](https://www.chessprogramming.org/Opening_Book) (PolyGlot format)

## Building

To build on *nix:

```
make
```

You can build with debugging symbols and no optimizations using:

```
make debug
```

If you have Mingw-w64 installed, you can cross compile for Windows on Linux with:

```
./build_windows.sh
```

## Documentation

Shallow Blue's code was extensively documented with Doxygen.
I tried to follow this rule in the Drofa, and mostly sucseeded.

To generate HTML documentation use:

```
doxygen
```

## Opening Books

Drofa, as Shallow Blue, supports PolyGlot formatted (`.bin`) opening books. To use an opening book, the `OwnBook`
and `BookPath` UCI options must be set to `true` and the path to the opening book file respectively.

These options can be set from your chess GUI or the UCI interface as follows:

```
setoption name OwnBook value true
setoption name BookPath value /path/to/book.bin
```

## Implemented non UCI Commands

These commands can be useful for debugging.

- `perft <depth>`
- Prints the perft value for each move on the current board to the specified depth
- `printboard`
- Pretty prints the current state of the game board
- `printmoves`
- Prints all legal moves for the currently active player

## License

I dont know shit about licensing and Drofa is too weak to be plagiarised.
So it is under the same MIT license as Shallow Blue.

2017-2019 © Rhys Rustad-Elliott (original Shallow Blue creator)
2020 © Litov Alexander

22 changes: 22 additions & 0 deletions build_windows.sh
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Cross compile script to build windows binaries
# Depends on Mingw-w64

export CC_FLAGS="-Wall -std=c++11 -O3 -flto -pthread -mtune=generic -fno-exceptions -static"
export LD_FLAGS="-pthread -flto -static"
export CXX=x86_64-w64-mingw32-g++-posix
make clean
make -j4
mv Drofa Drofa_x86-64.exe

export CC_FLAGS="-Wall -std=c++11 -O3 -flto -pthread -mtune=generic -static -m32"
export LD_FLAGS="-pthread -flto -static -m32"
export CXX=i686-w64-mingw32-g++-posix
make clean
make -j4
mv Drofa Drofa_x86.exe

echo -e "\n==========="
echo "Windows builds created"
echo "SHA256 sums"
sha256sum Drofa_x86.exe Drofa_x86-64.exe

0 comments on commit df886b1

Please sign in to comment.