Skip to content

Commit 03b51c1

Browse files
committed
Dockerize, fix some problems and improve readme
1 parent 0820d4f commit 03b51c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+366
-88
lines changed

.devcontainer/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM gcc:10.1
2+
3+
RUN apt update && apt install -y xboard
4+
5+
ENTRYPOINT []

.devcontainer/devcontainer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "cpp-chess",
3+
"dockerFile": "Dockerfile",
4+
"extensions": [
5+
"ms-vscode.cpptools"
6+
]
7+
}

.dockerignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Temporary files
2+
*~
3+
**/*~
4+
5+
# Auto generated files
6+
**/*.o
7+
**/*.d
8+
chess
9+
big_output.txt
10+
incoming.txt
11+
backup.pgn
12+
13+
src/error.txt
14+
**/*.dat

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
*~
33
*/*~
44

5-
# Eclipse files
6-
.project
7-
.cproject
8-
95
# Auto generated files
106
*.o
117
*.d
12-
Debug/*
138
chess
149
big_output.txt
1510
incoming.txt
1611
backup.pgn
1712

13+
src/error.txt

.vscode/c_cpp_properties.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [],
9+
"compilerPath": "/usr/bin/g++",
10+
"cStandard": "c11",
11+
"cppStandard": "c++20",
12+
"intelliSenseMode": "clang-x64"
13+
}
14+
],
15+
"version": 4
16+
}

.vscode/settings.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"git.ignoreLimitWarning": true,
3+
"files.associations": {
4+
"array": "cpp",
5+
"atomic": "cpp",
6+
"hash_map": "cpp",
7+
"hash_set": "cpp",
8+
"strstream": "cpp",
9+
"*.tcc": "cpp",
10+
"bitset": "cpp",
11+
"cctype": "cpp",
12+
"chrono": "cpp",
13+
"clocale": "cpp",
14+
"cmath": "cpp",
15+
"codecvt": "cpp",
16+
"complex": "cpp",
17+
"condition_variable": "cpp",
18+
"csignal": "cpp",
19+
"cstdarg": "cpp",
20+
"cstddef": "cpp",
21+
"cstdint": "cpp",
22+
"cstdio": "cpp",
23+
"cstdlib": "cpp",
24+
"cstring": "cpp",
25+
"ctime": "cpp",
26+
"cwchar": "cpp",
27+
"cwctype": "cpp",
28+
"deque": "cpp",
29+
"forward_list": "cpp",
30+
"list": "cpp",
31+
"unordered_map": "cpp",
32+
"unordered_set": "cpp",
33+
"vector": "cpp",
34+
"exception": "cpp",
35+
"rope": "cpp",
36+
"slist": "cpp",
37+
"fstream": "cpp",
38+
"functional": "cpp",
39+
"future": "cpp",
40+
"initializer_list": "cpp",
41+
"iomanip": "cpp",
42+
"iosfwd": "cpp",
43+
"iostream": "cpp",
44+
"istream": "cpp",
45+
"limits": "cpp",
46+
"memory": "cpp",
47+
"mutex": "cpp",
48+
"new": "cpp",
49+
"numeric": "cpp",
50+
"optional": "cpp",
51+
"ostream": "cpp",
52+
"ratio": "cpp",
53+
"shared_mutex": "cpp",
54+
"sstream": "cpp",
55+
"stdexcept": "cpp",
56+
"streambuf": "cpp",
57+
"string_view": "cpp",
58+
"system_error": "cpp",
59+
"thread": "cpp",
60+
"cinttypes": "cpp",
61+
"tuple": "cpp",
62+
"type_traits": "cpp",
63+
"typeindex": "cpp",
64+
"typeinfo": "cpp",
65+
"utility": "cpp",
66+
"valarray": "cpp",
67+
"*.ipp": "cpp",
68+
"variant": "cpp",
69+
"string": "cpp",
70+
"algorithm": "cpp"
71+
}
72+
}

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM gcc:10.1
2+
3+
RUN apt update && apt install -y xboard
4+
5+
WORKDIR /chess/src
6+
ADD src /chess/src
7+
8+
ARG DB=
9+
ARG XB=
10+
RUN DB=$DB XB=$XB make
11+
12+
ENTRYPOINT ["./chess"]

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
run: build
2+
docker run --rm -it --init --volume $(shell pwd)/tables:/chess/src/tables:rw --volume $(shell pwd)/xboard_commands:/chess/src/xboard_commands:rw --name chess chess
3+
4+
run_db: build_db
5+
docker run --rm -it --init --volume $(shell pwd)/tables:/chess/src/tables:rw --volume $(shell pwd)/xboard_commands:/chess/src/xboard_commands:rw --name chess_db chess_db
6+
7+
run_xb: build_xb
8+
docker run --rm -i --init --volume $(shell pwd)/tables:/chess/src/tables:rw --volume $(shell pwd)/xboard_commands:/chess/src/xboard_commands:rw --name chess_xb chess_xb
9+
10+
run_db_xb: build_db_xb
11+
docker run --rm -i --init --volume $(shell pwd)/tables:/chess/src/tables:rw --volume $(shell pwd)/xboard_commands:/chess/src/xboard_commands:rw --name chess_db_xb chess_db_xb
12+
13+
build_all: build build_db build_xb build_db_xb
14+
15+
build:
16+
docker build --tag chess .
17+
18+
build_db:
19+
docker build --build-arg DB=DB --tag chess_db .
20+
21+
build_xb:
22+
docker build --build-arg XB=XB --tag chess_xb .
23+
24+
build_db_xb:
25+
docker build --build-arg DB=DB --build-arg XB=XB --tag chess_db_xb .

README.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
1-
chess-cpp
2-
=========
1+
# chess-cpp
32

4-
Source code for the program made in my master thesis: Generation and compression of endgame tables in chess with fast random access using OBDDs.
3+
TLDR: Don't waste your time by looking here.
54

6-
Status for project is currently unknown, it's not well documented, etcetera.
5+
Source code (C++98) for the program made in my master thesis: Generation and compression of endgame tables in chess with fast random access using OBDDs.
6+
7+
8+
# Bugs
9+
10+
When I wrote this program I made use of several optimizations that we're based on how the compiler I was using happened to behave.
11+
In some cases this was a deliberate (but bad) choice. In most cases I didn't know better.
12+
13+
These are some of the mistakes that I've been hit by:
14+
* I assumed that a `char` was an unsigned 8 bit integer.
15+
* I assumed that I could write to one union member and read the corresponding bits from another union member
16+
17+
A few times I've tried to rectify the errors and make the program work again.
18+
But this is hard work with 35k lines of poorly documented code :-/
19+
20+
Currently large parts of it is working (in a dockerized build environment) but there are still significant problems.
21+
22+
Known bugs
23+
* Some short versions of commands causes crash (e.g. "ctfi ..." instead of "construct from table index ...")
24+
* With retrograde construction many (all?) invalid positions are stored as draw (-125) instead of illegal (-128). This reduces how much the tables can be compressed as OBDDs.
25+
* The 5 piece KPPKP endgame cannot be constructed as it contains a position with a depth to mate of 127 (`8/8/8/8/1p2P3/4P3/1k6/3K4 w - - 0 1`). This cannot fit in the `uint8_t` as values -124 and below are reserved.
26+
* When compiled against XBoard an error is logged when quitting the program (`free(): double free detected in tcache 2`)
27+
* Retrograde construction of KBNKP fails for a position with a pawn at an invalid square:
28+
```
29+
Error: Retrograde constr.: Player from index = 9217
30+
(it is 1 to move)
31+
Num checks = 0
32+
a b c d e f g h
33+
+-----------------+ |
34+
8 | | 8 | 50b
35+
7 | | 7 |
36+
6 | | 6 | White has lost castling
37+
5 | | 5 | Black has lost castling
38+
4 | | 4 |
39+
3 | | 3 | moves played since progress = 0
40+
2 | N | 2 |
41+
1 | k p K B | 1 |
42+
+-----------------+ |
43+
a b c d e f g h
44+
FEN: loadfen 8/8/8/8/8/8/N7/kpKB4 b - - 0 50
45+
```
46+
47+
48+
# What seems to work
49+
50+
* The endgames tables that are built seems to be correct. At least they are correct for some longest mates for 5 piece endgames ([test.com](src/test.com))
51+
* The chess engine can be used by xboard (tested with version 4.9.1). As command use `make run_xb` using the root of this repository as folder. This assumes you have docker installed. Maybe you should run `make run_xb` first to prebuild the image.

debugging/diff.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
Example:
3+
python debugging/diff.py tables/KBKP_wtm.dat tables/maybeok/KBKP_wtm.dat
4+
python debugging/diff.py tables/KNKP_wtm.dat tables/maybeok/KNKP_wtm.dat
5+
python debugging/diff.py tables/KNK_wtm.dat tables/maybeok/KNK_wtm.dat
6+
python debugging/diff.py tables/KPKP_wtm.dat tables/maybeok/KPKP_wtm.dat
7+
python debugging/diff.py tables/KPK_wtm.dat tables/maybeok/KPK_wtm.dat
8+
python debugging/diff.py tables/KQKB_wtm.dat tables/maybeok/KQKB_wtm.dat
9+
python debugging/diff.py tables/KQKN_wtm.dat tables/maybeok/KQKN_wtm.dat
10+
python debugging/diff.py tables/KQKP_btm.dat tables/maybeok/KQKP_btm.dat
11+
python debugging/diff.py tables/KQKP_wtm.dat tables/maybeok/KQKP_wtm.dat
12+
python debugging/diff.py tables/KQK_wtm.dat tables/maybeok/KQK_wtm.dat
13+
python debugging/diff.py tables/KQPK_wtm.dat tables/maybeok/KQPK_wtm.dat
14+
python debugging/diff.py tables/KRKP_wtm.dat tables/maybeok/KRKP_wtm.dat
15+
"""
16+
17+
import sys
18+
19+
def main(fn1, fn2, max_count):
20+
with open(fn1, "rb") as f:
21+
data1 = f.read()
22+
with open(fn2, "rb") as f:
23+
data2 = f.read()
24+
for i, (b1, b2) in enumerate(zip(data1, data2)):
25+
if b1 != b2:
26+
print("{} != {} at index {}".format(ord(b1), ord(b2), i))
27+
max_count -= 1
28+
if not max_count:
29+
break
30+
31+
main(sys.argv[1], sys.argv[2], int(sys.argv[3] if len(sys.argv) > 3 else 10))

0 commit comments

Comments
 (0)