A python based chess engine.
Welcome! This is Quark, a chess engine with the main aim of not beating Magnus, or even an amateur, but being able to play by itself. Currently it is a one-man-show running as a hobby project.
The engine is split up into two main components: the front-end and the back-end.
The front end is what the user interacts with. In the front end there is currently a ASCII art GUI which renders the board plus a UI so that the user isn’t manually changing the board state themselves. The UI will eventually work solely on traditional chess notation rules but currently it works on a special set of notational rules, which are outlined later on in this README.
In the back-end there is a complete chessboard, with rules, built from scratch. This engine uses a mailbox approach to storing the board state with 64 holes, each representing a single square on the board like so:
+---------------------------------------+
| 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
+---------------------------------------+
| 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
+---------------------------------------+
| 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
+---------------------------------------+
| 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
+---------------------------------------+
| 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+---------------------------------------+
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
+---------------------------------------+
| 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 |
+---------------------------------------+
| 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 |
+---------------------------------------+
However the engine is not required to work in indices.
Auxiliary to the engine, a class for vectors have been defined and used extensively in the methods and calculations of the engine. They behave mostly as 2D mathematical vectors, with sutble changes to methods to make them applicable to the engine. One example of this behaviour is in determing unit vectors; for a vector at a 45 degree bearing instead of making the unit vector (1/sqrt(2), 1/sqrt(2)) it is scaled up by sqrt(2) so that the indices are only integers, making it (1, 1).
The chess pieces are all individual classes that have their own specialised methods. They determine their moves using vector attack logic and uses the vector class for its mathematical grounding.
The search-and-evaluate part of the engine is currently being developed, and as such has no information pertaining to its inner workings yet.
My response to that question is why bother ever doing anything? It is done half as a hobby and half as a way to learn how large-scale projects behave. I am yet to write a program larger then 500 lines of code so I do not know yet what goes wrong when doing so.
Don’t expect this engine to ever beat anyone with half a brain in chess. I am hoping at best that it can play a game without breaking any rules.
The GUI currently looks like so:
+—————+
8 | rnbqkbnr |
7 | pppppppp |
6 | …….. |
5 | …….. |
4 | …….. |
3 | …….. |
2 | PPPPPPPP |
1 | RNBQKBNR |
+—————+
abcdefgh
where the capitalised pieces are on white while the lowercase pieces are on black.
The notational rules follow a format similar to traditional chess notation but with a bit more detail. Two examples of moves under the special notation would be “Qd1>a4” or “Pe4xd5” if this helps to make a bit more sense. A concrete set of rules are as follows:
The special symbols being used are identical to traditional chess. You are only required to specify the castling notation: the engine does the notation for checks, checkmates and promotions. So the rules are:
To play with the engine in its current state, simply run the main execution script ‘QuarkPlay.py’ as a module or script. To do this, in your terminal of choice type ‘python -m QuarkPlay’ or ‘python QuarkPlay.py’ while having the terminal’s working directory in the repository to run.
Currently there is no API, but it will be added as the project progresses further.
Under each individual method, class and function there are both unit tests and integrated tests to make sure that they are behaving in a sane manner. For more details of the tests written, please see the python scripts in the “tests” directory.
If you would like to contribute to the project, please visit one of the main contributor’s accounts and send them and email. We are always happy for more help.
This project is covered under the MIT license.