added stop UCI command + little adjustments
This commit is contained in:
1 parent
aaa3a72081
commit
81c52f05e3
5 files changed
+38
-10
No files matched your search
+1
-1
@@ -3,4 +3,4 @@ obj/
|
|||||||
|
|
||||||
# Ignore executable files
|
# Ignore executable files
|
||||||
*.exe
|
*.exe
|
||||||
Eleanor
|
Engine-Eleanor
|
||||||
@@ -2,6 +2,9 @@
|
|||||||
SRC_DIR := source
|
SRC_DIR := source
|
||||||
OBJ_DIR := obj
|
OBJ_DIR := obj
|
||||||
|
|
||||||
|
CXX := g++
|
||||||
|
EXE := Engine-Eleanor
|
||||||
|
|
||||||
# Determine platform
|
# Determine platform
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
EXE_EXT := .exe
|
EXE_EXT := .exe
|
||||||
@@ -16,12 +19,12 @@ SRCS := $(wildcard $(SRC_DIR)/*.cpp)
|
|||||||
OBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(SRCS:.cpp=.o)))
|
OBJS := $(addprefix $(OBJ_DIR)/, $(notdir $(SRCS:.cpp=.o)))
|
||||||
|
|
||||||
# Target executable
|
# Target executable
|
||||||
Engine-Eleanor$(EXE_EXT): $(OBJS)
|
$(EXE)$(EXE_EXT): $(OBJS)
|
||||||
g++ -o $@ $^ -O3
|
$(CXX) -o $@ $^ -O3
|
||||||
|
|
||||||
# Rule to compile source files to object files
|
# Rule to compile source files to object files
|
||||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/types.h | $(OBJ_DIR)
|
$(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
|
# Create the object directory if it doesn't exist
|
||||||
$(OBJ_DIR):
|
$(OBJ_DIR):
|
||||||
|
|||||||
+18
-5
@@ -62,10 +62,12 @@ void ListScores(Board &board) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static SearchResults Quiescence(Board board, int alpha, int beta) {
|
static SearchResults Quiescence(Board board, int alpha, int beta) {
|
||||||
|
if (searchStopped) return 0;
|
||||||
|
|
||||||
auto currTime = std::chrono::high_resolution_clock::now();
|
auto currTime = std::chrono::high_resolution_clock::now();
|
||||||
int elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(currTime - timeStart).count();
|
int elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(currTime - timeStart).count();
|
||||||
if (elapsed >= timeToSearch) {
|
if (elapsed >= timeToSearch) {
|
||||||
searchStopped = true;
|
StopSearch();
|
||||||
return 0;
|
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) {
|
static SearchResults PVS(Board board, int depth, int alpha, int beta) {
|
||||||
|
if (searchStopped) return 0;
|
||||||
|
|
||||||
auto currTime = std::chrono::high_resolution_clock::now();
|
auto currTime = std::chrono::high_resolution_clock::now();
|
||||||
int elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(currTime - timeStart).count();
|
int elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(currTime - timeStart).count();
|
||||||
if (elapsed >= timeToSearch) {
|
if (elapsed >= timeToSearch) {
|
||||||
searchStopped = true;
|
StopSearch();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,9 +196,6 @@ SearchResults ID(Board &board, SearchParams ¶ms) {
|
|||||||
safeResults = currentResults;
|
safeResults = currentResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "info nodes " << nodes << '\n';
|
|
||||||
std::cout << timeRemaining << std::endl;
|
|
||||||
|
|
||||||
if (searchStopped) break;
|
if (searchStopped) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,8 +204,20 @@ SearchResults ID(Board &board, SearchParams ¶ms) {
|
|||||||
|
|
||||||
void SearchPosition(Board &board, SearchParams ¶ms) {
|
void SearchPosition(Board &board, SearchParams ¶ms) {
|
||||||
searchStopped = false;
|
searchStopped = false;
|
||||||
|
|
||||||
|
|
||||||
SearchResults results = ID(board, params);
|
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()]
|
std::cout << "bestmove " << squareCoords[results.bestMove.MoveFrom()]
|
||||||
<< squareCoords[results.bestMove.MoveTo()] << '\n';
|
<< squareCoords[results.bestMove.MoveTo()] << '\n';
|
||||||
nodes = 0;
|
nodes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StopSearch() {
|
||||||
|
searchStopped = true;
|
||||||
|
std::cout << "Search stopped\n";
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void SearchPosition(Board &board, SearchParams ¶ms);
|
void SearchPosition(Board &board, SearchParams ¶ms);
|
||||||
|
void StopSearch();
|
||||||
|
|
||||||
constexpr int moveScoreTable[6][6] = {
|
constexpr int moveScoreTable[6][6] = {
|
||||||
105, 205, 305, 405, 505, 605,
|
105, 205, 305, 405, 505, 605,
|
||||||
|
|||||||
+12
-1
@@ -2,6 +2,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
@@ -163,7 +164,8 @@ void ParseGo(Board &board, std::string &command) {
|
|||||||
params.binc = ReadParam("binc", command);
|
params.binc = ReadParam("binc", command);
|
||||||
params.movesToGo = ReadParam("movestogo", 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) {
|
void UCILoop(Board &board) {
|
||||||
@@ -222,11 +224,20 @@ void UCILoop(Board &board) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse UCI "stop" command
|
||||||
|
if (input.find("stop") != std::string::npos) {
|
||||||
|
// stop the loop
|
||||||
|
StopSearch();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// parse UCI "uci" command
|
// parse UCI "uci" command
|
||||||
if (input.find("uci") != std::string::npos) {
|
if (input.find("uci") != std::string::npos) {
|
||||||
// print engine info
|
// print engine info
|
||||||
std::cout << "id name Eleanor\n";
|
std::cout << "id name Eleanor\n";
|
||||||
std::cout << "id name rektdie\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";
|
std::cout << "uciok\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user