added stop UCI command + little adjustments

This commit is contained in:
rektdie committed 2024-10-14 22:58:57 +02:00
1 parent aaa3a72081
commit 81c52f05e3
5 files changed
+39 -11

No files matched your search

+1 -1
View File
@@ -3,4 +3,4 @@ obj/
# Ignore executable files
*.exe
Eleanor
Engine-Eleanor
+6 -3
View File
@@ -2,6 +2,9 @@
SRC_DIR := source
OBJ_DIR := obj
CXX := g++
EXE := Engine-Eleanor
# Determine platform
ifeq ($(OS),Windows_NT)
EXE_EXT := .exe
@@ -16,12 +19,12 @@ SRCS := $(wildcard $(SRC_DIR)/*.cpp)
OBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(SRCS:.cpp=.o)))
# Target executable
Engine-Eleanor$(EXE_EXT): $(OBJS)
g++ -o $@ $^ -O3
$(EXE)$(EXE_EXT): $(OBJS)
$(CXX) -o $@ $^ -O3
# Rule to compile source files to object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/types.h | $(OBJ_DIR)
g++ -c -o $@ $< -O3
$(CXX) -c -o $@ $< -O3
# Create the object directory if it doesn't exist
$(OBJ_DIR):
+18 -5
View File
@@ -62,10 +62,12 @@ void ListScores(Board &board) {
}
static SearchResults Quiescence(Board board, int alpha, int beta) {
if (searchStopped) return 0;
auto currTime = std::chrono::high_resolution_clock::now();
int elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(currTime - timeStart).count();
if (elapsed >= timeToSearch) {
searchStopped = true;
StopSearch();
return 0;
}
@@ -109,10 +111,12 @@ static SearchResults Quiescence(Board board, int alpha, int beta) {
}
static SearchResults PVS(Board board, int depth, int alpha, int beta) {
if (searchStopped) return 0;
auto currTime = std::chrono::high_resolution_clock::now();
int elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(currTime - timeStart).count();
if (elapsed >= timeToSearch) {
searchStopped = true;
StopSearch();
return 0;
}
@@ -192,9 +196,6 @@ SearchResults ID(Board &board, SearchParams &params) {
safeResults = currentResults;
}
std::cout << "info nodes " << nodes << '\n';
std::cout << timeRemaining << std::endl;
if (searchStopped) break;
}
@@ -203,8 +204,20 @@ SearchResults ID(Board &board, SearchParams &params) {
void SearchPosition(Board &board, SearchParams &params) {
searchStopped = false;
SearchResults results = ID(board, params);
auto currTime = std::chrono::high_resolution_clock::now();
double elapsed = std::chrono::duration_cast<
std::chrono::duration<double>>(currTime - timeStart).count();
std::cout << "info " << nodes << " nodes " << nodes/elapsed << " nps\n";
std::cout << "bestmove " << squareCoords[results.bestMove.MoveFrom()]
<< squareCoords[results.bestMove.MoveTo()] << '\n';
nodes = 0;
}
void StopSearch() {
searchStopped = true;
std::cout << "Search stopped\n";
}
+1
View File
@@ -20,6 +20,7 @@ public:
};
void SearchPosition(Board &board, SearchParams &params);
void StopSearch();
constexpr int moveScoreTable[6][6] = {
105, 205, 305, 405, 505, 605,
+13 -2
View File
@@ -2,6 +2,7 @@
#include <iostream>
#include <algorithm>
#include <string>
#include <thread>
#include "types.h"
#include "movegen.h"
#include "search.h"
@@ -162,8 +163,9 @@ void ParseGo(Board &board, std::string &command) {
params.winc = ReadParam("winc", command);
params.binc = ReadParam("binc", command);
params.movesToGo = ReadParam("movestogo", command);
SearchPosition(board, params);
auto worker = std::thread(SearchPosition, std::ref(board), std::ref(params));
worker.detach();
}
void UCILoop(Board &board) {
@@ -222,11 +224,20 @@ void UCILoop(Board &board) {
break;
}
// parse UCI "stop" command
if (input.find("stop") != std::string::npos) {
// stop the loop
StopSearch();
continue;
}
// parse UCI "uci" command
if (input.find("uci") != std::string::npos) {
// print engine info
std::cout << "id name Eleanor\n";
std::cout << "id name rektdie\n";
std::cout << "option name Hash type spin default 1 min 1 max 1\n";
std::cout << "option name Threads type spin default 1 min 1 max 1\n";
std::cout << "uciok\n";
continue;
}