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 *.dll
*.so *.so
*.dylib *.dylib
blunderboard
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test

View file

@ -4,10 +4,15 @@ import (
"fmt" "fmt"
"github.com/notnil/chess" "github.com/notnil/chess"
"github.com/notnil/chess/uci" "github.com/notnil/chess/uci"
"math/rand" "math"
"time"
) )
// 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() { func main() {
engine, err := uci.New("stockfish") engine, err := uci.New("stockfish")
if err != nil { if err != nil {
@ -19,19 +24,28 @@ func main() {
panic(err) panic(err)
} }
rand.Seed(time.Now().UnixNano())
// random vs stockfish
game := chess.NewGame() game := chess.NewGame()
for game.Outcome() == chess.NoOutcome { for game.Outcome() == chess.NoOutcome {
moves := game.ValidMoves() if err := engine.Run(uci.CmdPosition{Position: game.Position()}, uci.CmdGo{Depth: 12}); err != nil {
game.Move(moves[rand.Intn(len(moves))])
if err := engine.Run(uci.CmdPosition{Position: game.Position()}, uci.CmdGo{MoveTime: time.Second / 100}); err != nil {
panic(err) 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(game.String()) fmt.Println("Illegal move!")
}
}
fmt.Println(game.Outcome())
fmt.Println(game.Position().Board().Draw()) fmt.Println(game.Position().Board().Draw())
} }