From 32a916129f9935ff25c92d152ca979f43c20e0d1 Mon Sep 17 00:00:00 2001 From: "0x90.space" Date: Wed, 4 Aug 2021 23:05:23 +0100 Subject: [PATCH] rate moves with stockfish-12 --- .gitignore | 1 + blunderboard.go | 36 +++++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 66fd13c..76482f2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.dll *.so *.dylib +blunderboard # Test binary, built with `go test -c` *.test diff --git a/blunderboard.go b/blunderboard.go index 4a83f0c..60eee17 100644 --- a/blunderboard.go +++ b/blunderboard.go @@ -4,10 +4,15 @@ import ( "fmt" "github.com/notnil/chess" "github.com/notnil/chess/uci" - "math/rand" - "time" + "math" ) +// stolen^H^H inspired from lichess https://github.com/ornicar/lila/blob/master/modules/analyse/src/main/Advice.scala#L79 +func WinningChance(cp int) float64 { + winning_chance := 2 / (1 + math.Exp(-0.004 * float64(cp))) - 1 + return winning_chance +} + func main() { engine, err := uci.New("stockfish") if err != nil { @@ -19,19 +24,28 @@ func main() { panic(err) } - rand.Seed(time.Now().UnixNano()) - - // random vs stockfish game := chess.NewGame() for game.Outcome() == chess.NoOutcome { - moves := game.ValidMoves() - game.Move(moves[rand.Intn(len(moves))]) - - if err := engine.Run(uci.CmdPosition{Position: game.Position()}, uci.CmdGo{MoveTime: time.Second / 100}); err != nil { + if err := engine.Run(uci.CmdPosition{Position: game.Position()}, uci.CmdGo{Depth: 12}); err != nil { panic(err) } - game.Move(engine.SearchResults().BestMove) + search_results := engine.SearchResults() + fmt.Println("Best Move: ", search_results.BestMove) + cp := search_results.Info.Score.CP + fmt.Println("Score (centipawns): ", cp) + winning_chance := WinningChance(cp) + fmt.Println("Winning chance: ", winning_chance) + fmt.Println(game.Position().Board().Draw()) + for { + var move string + fmt.Print("Move: ") + fmt.Scanln(&move) + if err := game.MoveStr(move); err == nil { + break + } + fmt.Println("Illegal move!") + } } - fmt.Println(game.String()) + fmt.Println(game.Outcome()) fmt.Println(game.Position().Board().Draw()) }