rate moves with stockfish-12
This commit is contained in:
parent
a236cff3c5
commit
32a916129f
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -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
|
||||||
|
|
|
@ -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("Illegal move!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fmt.Println(game.String())
|
fmt.Println(game.Outcome())
|
||||||
fmt.Println(game.Position().Board().Draw())
|
fmt.Println(game.Position().Board().Draw())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue