dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 1db6a3c87e360eae60a09c4003085455dc670ddd
parent b9b9107811619c379c3549559269423749ed64a5
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 18 Jun 2023 00:08:34 -0700

allow rerun analysis

Diffstat:
Mpkg/web/handlers/chess.go | 2+-
Mpkg/web/handlers/interceptors/chess.go | 18+++++++++++-------
2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go @@ -132,7 +132,7 @@ func ChessGameAnalyzeHandler(c echo.Context) error { if game.Outcome() == chess.NoOutcome { return c.String(http.StatusOK, "no outcome") } - if interceptors.ChessInstance.SetAnalyzing(key) { + if g.SetAnalyzing() { go func() { res, err := interceptors.AnalyzeGame(g, game.String()) if err != nil { diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -601,13 +601,9 @@ func (g *ChessGame) DrawSpectatorCard(moveIdx int, key string, isFlipped, sounds return g.drawPlayerCard(moveIdx, key, isFlipped, true, false, soundsEnabled, canUseChessAnalyze) } -func (b *Chess) SetAnalyzing(key string) bool { - b.Lock() - defer b.Unlock() - g, ok := b.games[key] - if !ok { - return false - } +func (g *ChessGame) SetAnalyzing() bool { + g.mtx.Lock() + defer g.mtx.Unlock() if g.analyzing { return false } @@ -615,6 +611,13 @@ func (b *Chess) SetAnalyzing(key string) bool { return true } +func (g *ChessGame) UnsetAnalyzing() { + g.mtx.Lock() + defer g.mtx.Unlock() + g.analyzing = false + g.analyzeProgrss = ChessAnalyzeProgress{} +} + func (b *Chess) IsAnalyzing(key string) (bool, error) { b.Lock() defer b.Unlock() @@ -997,6 +1000,7 @@ func AnalyzeGame(gg *ChessGame, pgn string) (out AnalyzeResult, err error) { } defer func() { pubProgress(nbPosition) + gg.UnsetAnalyzing() }() eng, err := uci.New("stockfish")