semi-fixed marlinformat
This commit is contained in:
1 parent
114ef9728a
commit
63f5c61063
3 files changed
+44
-91
No files matched your search
@@ -1,65 +0,0 @@
|
|||||||

|
|
||||||
# Eleanor is a chess engine
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- Bitboard board representation
|
|
||||||
- Magic Bitboards
|
|
||||||
- Legal move generation
|
|
||||||
- Precalculated attack tables
|
|
||||||
- Storing moves in a 16 bit word
|
|
||||||
- Copy/make moving
|
|
||||||
- Simple evaluation (material and piece-square tables, MVV-LVA)
|
|
||||||
- Principal Variation Search
|
|
||||||
- Move ordering
|
|
||||||
- Time management
|
|
||||||
- UCI
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
> Prerequisites:
|
|
||||||
> - A C++ compiler
|
|
||||||
> - Access to `make` command
|
|
||||||
|
|
||||||
1. Clone the repo to your PC
|
|
||||||
|
|
||||||
2. Run the command `make` in the root directory
|
|
||||||
> You can specify the compiler with the flag `CXX`
|
|
||||||
> and the executable name with `EXE`.
|
|
||||||
> By default they are `g++` and `Eleanor` respectively.
|
|
||||||
|
|
||||||
3. Run the executable
|
|
||||||
|
|
||||||
## How to use
|
|
||||||
There are some commands that you can use the engine with.
|
|
||||||
|
|
||||||
- **`position`**: Set the current position of the board with [FEN](https://www.chess.com/terms/fen-chess).
|
|
||||||
`position [FEN]` or `position startpos` can be used.
|
|
||||||
- **`ucinewgame`** resets the position and game state
|
|
||||||
- **`quit`** terminates the program
|
|
||||||
- **`go`** is the command that asks what is the best move in the current position (search),
|
|
||||||
but we have to give it some parameters:
|
|
||||||
`wtime` `btime` `winc` `binc`
|
|
||||||
The first letter tells the color of player
|
|
||||||
wtime sets the remaining time of the white player
|
|
||||||
and winc sets the increments for the white player.
|
|
||||||
**It's important that these parameters are given in milliseconds!**
|
|
||||||
- **`stop`** stops the current search
|
|
||||||
- **`bench`** tests the search speed of the engine on a set of positions
|
|
||||||
|
|
||||||
Also, the engine can be connected to any GUI software that has UCI support.
|
|
||||||
|
|
||||||
## Sources I used
|
|
||||||
[Chess Programming Wiki](https://www.chessprogramming.org/Main_Page "Chess Programming Wiki")
|
|
||||||
|
|
||||||
[Maksim Korzh's chess engine in C series](https://www.youtube.com/watch?v=QUNP-UjujBM&list=PLmN0neTso3Jxh8ZIylk74JpwfiWNI76Cs "Maksim Korzh's chess engine in C series")
|
|
||||||
|
|
||||||
[Stockfish discord helping community](https://discord.com/invite/GWDRS3kU6R "Stockfish discord community")
|
|
||||||
|
|
||||||
[Logo is generated by AI](https://deepai.org/ "Logo is generated by AI")
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
|
|
||||||
**The project is still in progress and developed constantly. Contributions are highly appreciated.**
|
|
||||||
|
|
||||||
###### Last edited: 2025-01-23
|
|
||||||
|
|
||||||
+24
-1
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
namespace DATAGEN {
|
namespace DATAGEN {
|
||||||
|
|
||||||
@@ -19,15 +20,37 @@ struct MarlinFormat {
|
|||||||
uint8_t extra; // 1 byte: Reserved for future use or additional data
|
uint8_t extra; // 1 byte: Reserved for future use or additional data
|
||||||
|
|
||||||
void packFrom(Board& board, int16_t eval, uint8_t wdl) {
|
void packFrom(Board& board, int16_t eval, uint8_t wdl) {
|
||||||
|
const uint8_t stm = board.sideToMove == Black ? (1 << 7) : 0;
|
||||||
|
|
||||||
occupancy = board.occupied;
|
occupancy = board.occupied;
|
||||||
pieces = UTILS::CompressPieces(board);
|
pieces = UTILS::CompressPieces(board);
|
||||||
uint8_t stm_ep_square = (board.sideToMove<< 7) | (board.enPassantTarget & 0x3F);
|
stmEPSquare = stm | (board.enPassantTarget == noEPTarget ? 64 : board.enPassantTarget);
|
||||||
|
|
||||||
halfmoveClock = board.halfMoves;
|
halfmoveClock = board.halfMoves;
|
||||||
fullmoveNumber = board.fullMoves;
|
fullmoveNumber = board.fullMoves;
|
||||||
this->eval = eval;
|
this->eval = eval;
|
||||||
this->wdl = wdl;
|
this->wdl = wdl;
|
||||||
extra = 0;
|
extra = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeToFile(const std::string& filename) const {
|
||||||
|
std::ofstream outFile(filename, std::ios::binary);
|
||||||
|
if (!outFile) {
|
||||||
|
std::cerr << "Error opening file for writing!" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
outFile.write(reinterpret_cast<const char*>(&occupancy), sizeof(occupancy));
|
||||||
|
outFile.write(reinterpret_cast<const char*>(&pieces), sizeof(pieces));
|
||||||
|
outFile.write(reinterpret_cast<const char*>(&stmEPSquare), sizeof(stmEPSquare));
|
||||||
|
outFile.write(reinterpret_cast<const char*>(&halfmoveClock), sizeof(halfmoveClock));
|
||||||
|
outFile.write(reinterpret_cast<const char*>(&fullmoveNumber), sizeof(fullmoveNumber));
|
||||||
|
outFile.write(reinterpret_cast<const char*>(&eval), sizeof(eval));
|
||||||
|
outFile.write(reinterpret_cast<const char*>(&wdl), sizeof(wdl));
|
||||||
|
outFile.write(reinterpret_cast<const char*>(&extra), sizeof(extra));
|
||||||
|
|
||||||
|
outFile.close();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ScoredMove {
|
struct ScoredMove {
|
||||||
|
|||||||
+20
-25
@@ -148,38 +148,33 @@ Move parseMove(Board &board, std::string_view str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::array<uint8_t, 16> CompressPieces(Board &board) {
|
std::array<uint8_t, 16> CompressPieces(Board &board) {
|
||||||
const uint8_t UNMOVED_ROOK = 0x08;
|
const uint8_t UNMOVED_ROOK = 6;
|
||||||
std::array<uint8_t, 16> compressed{};
|
std::array<uint8_t, 16> compressed{};
|
||||||
|
Bitboard occupancy = board.occupied;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
for (int square = 0; square < 64; square++) {
|
while (occupancy) {
|
||||||
int pieceCode = 0;
|
int square = occupancy.getLS1BIndex();
|
||||||
|
int pieceType = board.GetPieceType(square);
|
||||||
for (int pieceType = Pawn; pieceType <= King; pieceType++) {
|
int pieceCode = pieceType;
|
||||||
Bitboard pieceBitboard = board.pieces[pieceType];
|
|
||||||
|
|
||||||
if (pieceBitboard.IsSet(square)) {
|
|
||||||
if (board.colors[White] & board.pieces[pieceType]) {
|
|
||||||
pieceCode = pieceType; // White: 1-6
|
|
||||||
} else {
|
|
||||||
pieceCode = pieceType + 6; // Black: 7-12
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pieceType == Rook) {
|
if (pieceType == Rook) {
|
||||||
if ((board.colors[White] & board.pieces[Rook]) && (board.castlingRights & (whiteKingRight | whiteQueenRight))) {
|
if ((square == a1 && (board.castlingRights & whiteQueenRight))
|
||||||
pieceCode |= UNMOVED_ROOK;
|
|| (square == h1 && (board.castlingRights & whiteKingRight))
|
||||||
}
|
|| (square == a8 && (board.castlingRights & blackQueenRight))
|
||||||
if ((board.colors[Black] & board.pieces[Rook]) && (board.castlingRights & (blackKingRight | blackQueenRight))) {
|
|| (square == h8 && (board.castlingRights & blackKingRight)))
|
||||||
pieceCode |= UNMOVED_ROOK;
|
pieceCode = UNMOVED_ROOK;
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int byteIndex = square / 4;
|
pieceCode |= (board.sideToMove == Black ? (1 << 3) : 0);
|
||||||
int shift = (square % 4) * 4;
|
|
||||||
|
|
||||||
compressed[byteIndex] |= (pieceCode & 0x0F) << shift;
|
int byteIndex = index / 2;
|
||||||
|
int bitShift = (index % 2) * 4;
|
||||||
|
|
||||||
|
compressed[byteIndex] |= (pieceCode & 0x0F) << bitShift;
|
||||||
|
|
||||||
|
index++;
|
||||||
|
occupancy.PopBit(square);
|
||||||
}
|
}
|
||||||
|
|
||||||
return compressed;
|
return compressed;
|
||||||
|
|||||||
Reference in new issue
Block a user