Skip to content

Commit

Permalink
Add the Analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielCTroia committed Nov 25, 2021
1 parent 530e308 commit cee9547
Show file tree
Hide file tree
Showing 6 changed files with 3,844 additions and 36 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ RUN echo "arch:$( uname -m )" \
;; \
esac

FROM alpine:latest
# FROM alpine:latest
# # Common build stage
FROM mhart/alpine-node:14 as common-build-stage

LABEL maintainer="[email protected]"
LABEL project="https://github.com/tchorwat/stockfish"

Expand All @@ -46,12 +49,9 @@ COPY --chown=stockfish:stockfish --from=builder /Stockfish/Copying.txt /stockfis
COPY --chown=stockfish:stockfish source.txt /stockfish/
COPY --chown=stockfish:stockfish --from=builder /Stockfish/src/*.nnue /stockfish/

# EXPOSE 23249
EXPOSE 23249
# ENTRYPOINT ["/entrypoint.sh"]

# # Common build stage
FROM node:16 as common-build-stage

WORKDIR /

COPY . ./app
Expand Down
56 changes: 50 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,64 @@
import bodyParser from "body-parser";
import { GameRecord } from "dstnd-io";
import express, { Application, Request, Response } from "express";
import { Engine } from "node-uci";
import { Analyzer, GameToAnalyze } from "./src/Engine";

const app: Application = express();
const port = 6000;
const port = 5454;

// Body parsing Middleware
app.use(express.json());
// app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.get("/", async (req: Request, res: Response): Promise<Response> => {
return res.status(200).send({
message: "Hello World!",
app.use(bodyParser.json());

const analyzersByGameId: Record<GameRecord["id"], Analyzer> = {};

const getExistentAnalyzerOrCreateNew = (game: GameToAnalyze) => {
const { [game.id]: engine } = analyzersByGameId;

if (engine && !engine.hasQuit) {
return engine;
}

analyzersByGameId[game.id] = new Analyzer(game, {
searchOpts: { depth: 10, nodes: 25000 },
});

return analyzersByGameId[game.id];
};

app.post("/analyze", async (req: Request, res: Response) => {
try {
const { gameId, fen } = req.body;

if (!(gameId && fen)) {
throw new Error("Body not good");
}

const engine = getExistentAnalyzerOrCreateNew({ id: gameId, fen });

const engineRes = await engine.updateAndSearchOnce(fen);

// console.log("engine res", engineRes);

return res.status(200).send({
// message: "ok",
// works: 'good',
// ...req.body,
...engineRes,
});
} catch (e) {
console.error("Stockfish errror", e);
return res.status(500).send({
error: e,
});
}
});

try {
app.listen(port, (): void => {
app.listen(port, () => {
console.log(`Connected successfully on port ${port}`);
});
} catch (error) {
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"dependencies": {
"@types/express": "^4.17.13",
"@types/node": "^16.11.10",
"express": "^4.17.1"
"@types/node-uci": "^1.3.1",
"body-parser": "^1.19.0",
"dstnd-io": "https://github.com/dstnd/dstnd-io.git#v0.2.2",
"express": "^4.17.1",
"node-uci": "^1.3.4"
}
}
229 changes: 229 additions & 0 deletions results/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
{
"message": {
"bestmove": "c6d4",
"info": [
{ "string": "NNUE evaluation using nn-13406b1dcbe0.nnue enabled" },
{
"depth": 1,
"seldepth": 1,
"time": 2,
"nodes": 122,
"nps": 61000,
"tbhits": 0,
"score": { "unit": "cp", "value": -36 },
"multipv": 1,
"pv": "a7a6"
},
{
"depth": 1,
"seldepth": 1,
"time": 2,
"nodes": 122,
"nps": 61000,
"tbhits": 0,
"score": { "unit": "cp", "value": -39 },
"multipv": 2,
"pv": "g8f6"
},
{
"depth": 1,
"seldepth": 1,
"time": 2,
"nodes": 122,
"nps": 61000,
"tbhits": 0,
"score": { "unit": "cp", "value": -52 },
"multipv": 3,
"pv": "c6d4"
},
{
"depth": 1,
"seldepth": 1,
"time": 2,
"nodes": 122,
"nps": 61000,
"tbhits": 0,
"score": { "unit": "cp", "value": -52 },
"multipv": 4,
"pv": "f8c5"
},
{
"depth": 2,
"seldepth": 2,
"time": 2,
"nodes": 277,
"nps": 138500,
"tbhits": 0,
"score": { "unit": "cp", "value": 22 },
"multipv": 1,
"pv": "f8d6 b5c6 d7c6"
},
{
"depth": 2,
"seldepth": 2,
"time": 2,
"nodes": 277,
"nps": 138500,
"tbhits": 0,
"score": { "unit": "cp", "value": -2 },
"multipv": 2,
"pv": "g8f6 b5c6"
},
{
"depth": 2,
"seldepth": 2,
"time": 2,
"nodes": 277,
"nps": 138500,
"tbhits": 0,
"score": { "unit": "cp", "value": -20 },
"multipv": 3,
"pv": "f8c5 b5c6"
},
{
"depth": 2,
"seldepth": 2,
"time": 2,
"nodes": 277,
"nps": 138500,
"tbhits": 0,
"score": { "unit": "cp", "value": -52 },
"multipv": 4,
"pv": "c6d4 f3d4"
},
{
"depth": 3,
"seldepth": 4,
"time": 3,
"nodes": 744,
"nps": 248000,
"tbhits": 0,
"score": { "unit": "cp", "value": -37 },
"multipv": 1,
"pv": "g8f6 b1c3 c6d4 f3d4 e5d4"
},
{
"depth": 3,
"seldepth": 3,
"time": 3,
"nodes": 744,
"nps": 248000,
"tbhits": 0,
"score": { "unit": "cp", "value": -52 },
"multipv": 2,
"pv": "c6d4 f3d4 e5d4"
},
{
"depth": 3,
"seldepth": 4,
"time": 3,
"nodes": 744,
"nps": 248000,
"tbhits": 0,
"score": { "unit": "cp", "value": -54 },
"multipv": 3,
"pv": "g8e7 b1c3 c6d4 f3e5"
},
{
"depth": 3,
"seldepth": 3,
"time": 3,
"nodes": 744,
"nps": 248000,
"tbhits": 0,
"score": { "unit": "cp", "value": -76 },
"multipv": 4,
"pv": "g7g6 d2d4 e5d4"
},
{
"depth": 4,
"seldepth": 4,
"time": 4,
"nodes": 1880,
"nps": 470000,
"tbhits": 0,
"score": { "unit": "cp", "value": -51 },
"multipv": 1,
"pv": "g8f6 d2d3 d7d6 b1c3"
},
{
"depth": 4,
"seldepth": 4,
"time": 4,
"nodes": 1880,
"nps": 470000,
"tbhits": 0,
"score": { "unit": "cp", "value": -63 },
"multipv": 2,
"pv": "g8e7 d2d4 e5d4"
},
{
"depth": 4,
"seldepth": 4,
"time": 4,
"nodes": 1880,
"nps": 470000,
"tbhits": 0,
"score": { "unit": "cp", "value": -66 },
"multipv": 3,
"pv": "f8c5 b1c3 c6d4 f3e5"
},
{
"depth": 4,
"seldepth": 4,
"time": 4,
"nodes": 1880,
"nps": 470000,
"tbhits": 0,
"score": { "unit": "cp", "value": -96 },
"multipv": 4,
"pv": "c6d4 f3d4 e5d4 e1g1"
},
{
"depth": 5,
"seldepth": 5,
"time": 5,
"nodes": 2502,
"nps": 500400,
"tbhits": 0,
"score": { "unit": "cp", "value": -57 },
"multipv": 1,
"pv": "c6d4 f3d4 e5d4 e1g1 c7c6"
},
{
"depth": 5,
"seldepth": 5,
"time": 5,
"nodes": 2502,
"nps": 500400,
"tbhits": 0,
"score": { "unit": "cp", "value": -66 },
"multipv": 2,
"pv": "g8f6 d2d3"
},
{
"depth": 4,
"seldepth": 4,
"time": 5,
"nodes": 2502,
"nps": 500400,
"tbhits": 0,
"score": { "unit": "cp", "value": -63 },
"multipv": 3,
"pv": "g8e7 d2d4 e5d4"
},
{
"depth": 4,
"seldepth": 4,
"time": 5,
"nodes": 2502,
"nps": 500400,
"tbhits": 0,
"score": { "unit": "cp", "value": -66 },
"multipv": 4,
"pv": "f8c5 b1c3 c6d4 f3e5"
}
],
"ponder": "f3d4"
}
}
Loading

0 comments on commit cee9547

Please sign in to comment.