rate moves with stockfish-12

This commit is contained in:
0x90.space 2021-08-04 23:05:23 +01:00
parent a236cff3c5
commit 32a916129f
2 changed files with 26 additions and 11 deletions

1
.gitignore vendored
View file

@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
blunderboard
# Test binary, built with `go test -c`
*.test

View file

@ -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())
}