dkforest

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

commit f1f1e712778c710085ac3e5ad1bd5c35b9edcea4
parent fe26af983862ad7162c9e02ad2468f58b61de5e5
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 14 Jun 2023 02:45:18 -0700

specify analyse time

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

diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go @@ -92,7 +92,7 @@ var cssReset = `<style> func ChessAnalyseHandler(c echo.Context) error { pgn := `1. d4 Nf6 2. Nf3 e6 3. Bf4 { A46 Indian Defense: London System } c5 4. e3 d5 5. c3 Bd6 6. Bg3 O-O 7. Bd3 Qc7 8. Bxd6 Qxd6 9. O-O Nbd7 10. Nbd2 e5 11. dxe5 Nxe5 12. Nxe5 Qxe5 13. Nf3 Qe7 14. b3 Rd8 15. Rc1 Bg4 16. Be2 Bf5 17. Bd3 Ne4 18. Qc2 Rd6 19. Rfd1 Re8 20. Bb5?! { (-0.28 → -0.96) Inaccuracy. Bxe4 was best. } (20. Bxe4) 20... Rc8 21. Bd3 Rcd8 22. Nd2 h6 23. Nxe4 dxe4 24. Bc4 b6 25. Rxd6 Qxd6 26. h3 a5 27. Qe2 Qd2 28. Qxd2 Rxd2 29. a4?! { (-0.06 → -0.70) Inaccuracy. b4 was best. } (29. b4 Be6 30. Bxe6 fxe6 31. bxc5 bxc5 32. Rb1 Rxa2 33. Rb5 a4 34. Rxc5 Kf7 35. Rc6 Ke7) 29... Be6?! { (-0.70 → -0.13) Inaccuracy. Kf8 was best. } (29... Kf8 30. b4 Ke7 31. bxc5 bxc5 32. Rb1 Be6 33. Bxe6 Kxe6 34. g4 Rc2 35. Rb6+ Kd5 36. Rb5) 30. Bxe6 fxe6 31. Rb1 Kf7 32. Kf1 Rc2 33. c4 h5 34. g4 hxg4 35. hxg4 Kf6 36. Kg2 Ke5 37. Kg3 Rd2 38. f3?? { (0.00 → -5.42) Blunder. Kg2 was best. } (38. Kg2 Kf6 39. Kg3 Kg5 40. Rh1 Rb2 41. Rh8 Rxb3 42. Re8 Rb4 43. Rxe6 Rxa4 44. Rxb6 Rxc4) 38... Re2 39. f4+ Kf6 40. g5+ Kf5 41. Rh1 Rxe3+ 42. Kh4 Rxb3 43. g6 Kxf4 44. Kh5?! { (-12.25 → Mate in 15) Checkmate is now unavoidable. Rg1 was best. } (44. Rg1 e3 45. Rg4+ Kf3 46. Rg3+ Ke2 47. Kg4 Kd2 48. Kf4 Rd3 49. Ke4 Rd4+ 50. Ke5 e2) 44... Ra3?! { (Mate in 15 → -55.05) Lost forced checkmate sequence. Rf3 was best. } (44... Rf3 45. Rh4+ Kf5 46. Rh2 e3 47. Kh4 Rf2 48. Rh1 Kf4 49. Kh3 e2 50. Re1 Kf3 51. Kh4) 45. Rf1+?! { (-55.05 → Mate in 11) Checkmate is now unavoidable. Kh4 was best. } (45. Kh4 Rf3 46. Rg1 e3 47. Rg4+ Kf5 48. Rg2 Ke4 49. Ra2 Kf4 50. Rg2 Rf2 51. Rg4+ Kf5) 45... Rf3 46. Rxf3+ exf3 47. Kh4 f2 48. Kh3 Kf3 49. Kh2 f1=R 50. Kh3` //Rh1# { Black wins by checkmate. } 0-1` - res, err := interceptors.AnalyseGame(pgn) + res, err := interceptors.AnalyseGame(pgn, 60) if err != nil { return c.String(http.StatusOK, err.Error()) } @@ -138,7 +138,12 @@ func ChessGameAnalyseHandler(c echo.Context) error { if game.Outcome() == chess.NoOutcome { return c.String(http.StatusOK, "no outcome") } - res, err := interceptors.AnalyseGame(game.String()) + t := utils.DoParseInt64(c.QueryParam("t")) + if t == 0 { + t = 15 + } + t = utils.Clamp(t, 1, 60) + res, err := interceptors.AnalyseGame(game.String(), t) if err != nil { return c.String(http.StatusOK, err.Error()) } diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -758,7 +758,7 @@ type AnalyseResult struct { BlackAccuracy float64 } -func AnalyseGame(pgn string) (out AnalyseResult, err error) { +func AnalyseGame(pgn string, t int64) (out AnalyseResult, err error) { // https://github.com/lichess-org/lila/blob/9204a337492c1be4b7b8dabd68941d8934439cbc/modules/analyse/src/main/AccuracyPercent.scala#L71 // sbt 'testOnly lila.analyse.AccuracyPercentTest' // lichess: 86% 97% (game against stockfish) @@ -789,13 +789,16 @@ func AnalyseGame(pgn string) (out AnalyseResult, err error) { cps := make([]int, 0) + t = utils.Clamp(t, 1, 60) + moveTime := time.Duration((float64(t)/float64(len(positions)-1))*1000) * time.Millisecond + for idx, position := range positions { // First position is the board without any move played if idx == 0 { continue } cmdPos := uci.CmdPosition{Position: position} - cmdGo := uci.CmdGo{MoveTime: time.Second} + cmdGo := uci.CmdGo{MoveTime: moveTime} if err := eng.Run(cmdPos, cmdGo); err != nil { logrus.Fatal(err) }