WillGarrison1 / Pioneer

A little chess engine I'm working on
GNU General Public License v3.0
2 stars 0 forks source link

can't compile on Linux : solved (partly) #1

Closed tissatussa closed 2 months ago

tissatussa commented 3 months ago

i found your chess engine at https://chessengines.blogspot.com/2024/07/new-chess-engine-pioneer-301.html and then i found your GitHub page of this project. Compiling gave many warnings and errors. It seems you created the code mainly for Windows, so i had to adjust some code to make it run on Linux. I succeeded (with the help of ChatGPT) but Pioneer doesn't play a flawless game (i use CuteChess GUI) .. i had to make a nasty hack to prevent it losing on time, see below.

i will point out what i discovered and what i changed in the code, for you to create a better version, and for me to document my efforts.

i don't use VS and there's no Makefile, so i compiled like this :

$ g++-13 ./core/Representation/bitboard.cpp ./core/Representation/board.cpp ./core/Representation/direction.cpp ./core/Search/evaluate.cpp ./main.cpp ./core/MoveGeneration/movegen.cpp ./core/Search/moveOrder.cpp ./core/Representation/piece.cpp ./core/Search/search.cpp ./microbench/systemtime.cpp ./core/Search/transposition.cpp ./uci.cpp -O3 -std=c++20 -march=native -Ofast -lpthread -lm -o ./Pioneer

first of all, i had to replace all backward slashes in paths into forward slashes, because Linux needs that, eg. 5 paths in uci.cpp :

#include "core/Search/evaluate.h"
#include "core/Representation/bitboard.h"
#include "core/Search/moveOrder.h"
#include "core/MoveGeneration/movegen.h"
#include "microbench/microbench.h"

Btw. here i also had to adjust the folder name representation into Representation .. Windows doesn't mind the (non)capital letter, but Linux does .. i advise you to use only non-capital letters in all file and folder names, to avoid any such issues, it's common practice.

to avoid a warning () i had to add casting to many OR-constructs (in uci.cpp, piece.cpp, movegen.cpp and board.cpp), like this : ) warning: bitwise operation between different enumeration types ‘Pieces::Color’ and ‘Pieces::PieceType’ is deprecated [-Wdeprecated-enum-enum-conversion]

char pieceToChar(Piece piece) {
    switch (piece) {
        case static_cast<int>(Pieces::White) | static_cast<int>(Pieces::Pawn):
            return 'P';
        (...)
    }
    (...)
}

also in uci.cpp i changed this line :

// Normal search
cout << "info string Normal search to depth " << depthValue << "\n";

here i added the prefix "info string" because the UCI protocol demands it (although CuteChess will kindly accept any output without that prefix).

in main.cpp i removed the last line ..

cout << "\n";

..because your empty lines aren't needed and they are uncommon.

in search.cpp i altered the PV output like this :

cout << "info depth " << i << " score cp " << bestMove.value << " nodes "
     << diagnostics.nodes << " nps "
     << diagnostics.nodes * 1000 / (currentTime - startDepthTime + 1)
     << " time " << (currentTime - startDepthTime)
     << " hashfull " << used
     << " pv " << moveToString(bestMove.move)
     << std::endl;

here several changes were made :

i also got a warning due to the code in function Board::printFEN() in board.cpp :

./core/Representation/board.cpp: In member function ‘void Board::printFEN()’:
./core/Representation/board.cpp:180:15: warning: iteration 64 invokes undefined behavior [-Waggressive-loop-optimizations]
  180 |         Piece piece = board[square-1];
      |               ^~~~~
./core/Representation/board.cpp:172:34: note: within this loop
  172 |     for (int square = 64; square >= 0; square--) {
      |                           ~~~~~~~^~~~

ChatGPT explained to me you're counting 0-64, not 0-63, and so the index may be out of bounds .. i'm not very familiar with C++ and it could work, but better avoid the warning, so i changed this function to the one ChatGPT gave me :

void Board::printFEN() {
    int open = 0;
    for (int square = 63; square >= 0; square--) {  // Start from 63 to 0
        if (square % 8 == 7) {  // Check if we are at the beginning of a new row
            if (open) {
                std::cout << open;
                open = 0;
            }
            if (square != 63) {  // Avoid printing '/' at the start
                std::cout << "/";
            }
        }
        Piece piece = board[square];
        if (piece) {
            if (open) {
                std::cout << open;
                open = 0;
            }
            std::cout << pieceToChar(piece);
        } else {
            open += 1;
        }
    }
    if (open) {
        std::cout << open;
    }
}

in bitboard.h i got 2 warnings about (template) functions returning nothing while they should .. so i changed that like this :

template <>
Bitboard getAttackBB<Pieces::Pawn>(int s) {
    return 0ULL;
}

same for the 'getAttackBB' Queen function. i hope my solution "return 0ULL" is correct, but it seems to work.

after all that, compilation had no more warnings and errors, it created a valid binary of 81.1 Kb which runs in CuteChess. But that Pioneer version loses on time easily .. i found the engine can give a bestmove, but time management seems flawed, eg. when playing a 5m+3s game, bestmove is given after about 7 minutes at depth 10 (tested in terminal) .. i looked into your time management functions but it's hard to discover an error .. i found you use some "max nodes" and "max depth" and "max time" .. it's all unclear to me. So, to let Pioneer play a game in CuteChess anyhow, i made a nasty hack by setting "nodesCount = 3700000" in uci.cpp .. this seems to solve the issue : now Pioneer can play a decent game, it seems to act upon that max nodes, but you should solve this (probably you'd already noticed this shortcoming yourself).

see my ChatGPT session for details.

last thing : your package states "V3.01" and also V0.3 !?

maybe my efforts wouldn't be needed while you're actively working on the engine .. anyhow, it was a pleasure to fix those warnings and errors, i learned a lot ! btw. i didn't try your Python scripts.

[ i'm on Xubuntu 22.04 ]

WillGarrison1 commented 3 months ago

I'm glad you fixed the issues you were facing, this project knows that ChatGPT can be a very helpful tool :)

I'm new to managing open-source projects, but I'll start working on a makefile and fixing the issues you found. Thanks for the feedback!

tissatussa commented 3 months ago

I'm glad you fixed the issues you were facing..

yeah, but some of them were 'hacks', eg. max nodes - it should alert you something's wrong ..

..this project knows that ChatGPT can be a very helpful tool

so you also use ChatGPT for coding ? My experience is not always positive, this AI might give solutions and constructs which are invalid, but then it turns out the AI just presents them as being known functions / correct syntax, and they don't .. always double check its answers and ask them again in a slightly different way.

I'm new to managing open-source projects..

i know those GitHub commands and constructs are not easy .. i never did a GitHub coding project yet .. once i let someone show me how it all works, but i don't remember all of it ..

..I'll start working on a makefile..

that's a good thing, worth every penny !

..and fixing the issues you found..

some may be hard, so let it all sink in. "it's about the way, not the goal" .. have fun and learn !

Thanks for the feedback!

i'll receive a notification when you made any progress. if you want me to test code on Linux, i'm glad to help.

tissatussa commented 2 months ago

i managed to compile your v0.3.2 source on Linux, using the supplied g++ command. I didn't have to change any code, I only had to adjust 2 folder names : core/representation and core/search, both had a capital first letter so Linux didn't find them .. i encourage you to use only small letters for all files and folders.

the program runs fine in CuteChess GUI, but only with go movetime, as you stated .. you should try to implement go with wtime and btime (and bonus time) so it can fully compete with other engines in CuteChess.

i'm closing this Issue now, because it's all solved!

WillGarrison1 commented 2 months ago

Great, thanks for checking it out!