-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
130 lines (101 loc) · 4.55 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <bitset>
#include "process_pgn/read_pgn_data.hpp"
#include "cli.hpp"
#include "representation/position.hpp"
#include "engine/search.hpp"
#include "tablebase/zobrist.hpp"
#include <unordered_map>
int main(int argc, char *argv[])
{
CLI cli;
cli.process_command_read_tablebases({"read_tablebases", "latest"});
cli.cli_loop();
}
/*
High-level Design.
main server thread waits for user input, and asks the engine to do stuff.
server should start it's own thread for engine tasks, engine operation shouldnt block CLI.
Engine should manage its own threadpool.
Things that the server can do:
Can ask the PgnProcessor to create_tablebases from pgn files.
Can ask the engine to load tablebases from disk into memory, for use.
Can ask the engine to set up the current position
Can ask the engine to find the best move (given the engine's position)
Can ask the engine to stop searching, and report back the best thing it's found so far
Can ask the engine to set options
Think of CLI as server, and of the different commands as endpoints.
Looking at it this way, it's much clearer that the server owns the engine.
----------
*/
/*
Tasks
- Castling
- Legal move generation
- Move cannot cause mover's king to be in check
- Mover's king cannot be in check, and cannot pass through check during
- Move representation (i.e. e2e4 or [16,32])
- Opening book (for up to 4/5 moves) https://www.chessprogramming.org/ECO
- endgame tablebases
castling
- Position Evaluation Function
- Chess Engine that plays random legal moves, and is rule complete.
Another drawback is that tablebases require a lot of memory to store the many
thousands of positions. The Nalimov tablebases, which use advanced compression
techniques, require 7.05 GB of hard disk space for all 5-piece endings. The
6-piece endings require approximately 1.2 TB.[39][40] The 7-piece Lomonosov
tablebase requires 140 TB of storage space.[41]
*/
/*
Methods for finding legal moves from pseudolegal moves
Naive: For every move, iterate through opponents piece list and see if
they are attacking the king
Slightly better: For every move, check diagonals for enemy bishops/queens,
files/ranks for enemy rooks/queens, knight-hops for enemy knights,
pawn-captures for enemy pawns, and king captures for enemy kings. Then you
don't have to maintain a piece list.
Start with naive.
If it's really slow then user a profiler to improve it.
*/
/*
TODO
- change raw pointers to unique and shared ptrs
- Consider how to go about error handling (for invalid FEN strings for example)
- Look into setoptions
one option could be threadcount
- clean up header files so that foo.cpp and foo.hpp arent including the same
things
- add more assertions
- refactor code
- smaller functions
- better interfaces
- Make it work on linux (again)
- Create an OS-agnostic setup w.r.t file locations and Cmake files
- After finishing PGN parser, consider rethinking data structures for main chess engine.
- Consider using bitboards and piece sets again
- Think about memory model, work on design for what exactly will be going on
in the minimax position evaluation algorithm
- Possible optimization: positional metadata (probably known as attack and defend sets),
such as a list of pieces that attack the king,
can be stored on the position and saved to be used later, and can be made immutable
and shared between positions (as long as it doesnt change).
- Make move and unmake move - write these functions correctly and you don't have to do nearly
as much allocation during position search
CHAPTER 1: PGN READER + SERIALIZED OPENING TABLEBASE
CHAPTER 2: READ MORE CHESSPROGRAMMING WIKI
CHAPTER 3: RESEARCH SEARCH ALGORITHM (MINMAX) AND UNDERSTAND MEMORY MODEL
CHAPTER 4: REVISE DATA STRUCTURES AND BOARD/PIECE REPRESENTATION
(after research, and learnings from flaws of pgn reader approach)
CHAPTER 5: IMPLEMENT BASIC POSITION EVALUATION FUNCTION + MINMAX
CURRENT GOALS:
- Implement minimum uci commands necessary to have barebones legal engine
- Successfully play 5 hardcoded moves from queens gambit line as white in UI,
connected to engine
- Generate opening tablebase from PGN files.
- Have engine play as deep as it can from opening tablebase, picking moves at random,
with the popularity of the move determining the probability.
MAIN GOALS:
- play via the arena UCI-friendly GUI
- make a computer that can beat you, and your friends
- engineer a readable and well-designed implementation that you are proud of (not a spaghetti mess)
- learn lots of C++ in the process
*/