read real game from pgn

main
0x90.space 2021-08-28 21:34:07 +01:00
parent bf8c1f3728
commit 039bb04934
2 changed files with 37 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/notnil/chess"
"github.com/notnil/chess/uci"
"math"
"os"
)
// stolen^H^H inspired from lichess https://github.com/ornicar/lila/blob/master/modules/analyse/src/main/Advice.scala#L79
@ -14,6 +15,17 @@ func WinningChance(cp int) float64 {
}
func main() {
reader, err := os.Open("spongeboyahoy_vs_tomlx.pgn")
if err != nil {
panic(err)
}
pgn, err := chess.PGN(reader)
if err != nil {
panic(err)
}
spongeboyahoy_vs_tomlx := chess.NewGame(pgn)
fmt.Println(spongeboyahoy_vs_tomlx)
engine, err := uci.New("stockfish")
if err != nil {
panic(err)
@ -49,14 +61,16 @@ func main() {
} else {
fmt.Print("Ok")
}
fmt.Printf(" (%0.2f)\n", -delta)
fmt.Printf(" (%0.2f, %0.2f, %0.2f)\n", float64(cp) / 100, winning_chance, -delta)
}
prevprev_winning_chance = prev_winning_chance
prev_winning_chance = winning_chance
fmt.Println(game.Position().Board().Draw())
fmt.Println("Score (centipawns):", cp, "Winning chance:", winning_chance, "Best Move: ", search_results.BestMove)
fmt.Println("Move: ", search_results.BestMove)
if err := game.Move(search_results.BestMove); err != nil {
// fmt.Println(game.Position().Board().Draw())
// fmt.Println("Score (centipawns):", cp, "Winning chance:", winning_chance, "Best Move: ", search_results.BestMove)
// fmt.Println("Move: ", search_results.BestMove)
move := spongeboyahoy_vs_tomlx.Moves()[num_of_moves]
fmt.Print(num_of_moves / 2 + 1, move, "\t")
if err := game.Move(move); err != nil {
panic(err)
}
// for {

View File

@ -0,0 +1,18 @@
[Event "Casual Blitz game"]
[Site "https://lichess.org/uRulHisz"]
[Date "2021.08.06"]
[White "spongeboy_ahoy"]
[Black "tomlx"]
[Result "1-0"]
[UTCDate "2021.08.06"]
[UTCTime "19:59:25"]
[WhiteElo "843"]
[BlackElo "1229"]
[Variant "Standard"]
[TimeControl "300+3"]
[ECO "C00"]
[Opening "French Defense: Steinitz Attack"]
[Termination "Time forfeit"]
1. e4 e6 2. e5 d5 3. exd6 cxd6 4. Nc3 Nc6 5. Bb5 a6 6. Ba4 b5 7. Bb3 d5 8. a4 Bb7 9. axb5 axb5 10. Rxa8 Qxa8 11. Nxb5 Qa5 12. c4 Ba6 13. Nc3 Bxc4 14. Bxc4 dxc4 15. Qg4 Qa1 16. Nge2 Nf6 17. Qxc4 Na7 18. O-O Bd6 19. d3 O-O 20. Be3 Qxb2 21. Na4 Qa3 22. Bc1 Qb4 23. Nd4 Qxc4 24. dxc4 Ng4 25. h3 Ne5 26. Be3 Nxc4 27. Nb3 Rb8 28. Rb1 Nb5 29. Ba7 Rb7 30. Bc5 Bxc5 31. Nbxc5 Rc7 32. Na6 Rc6 33. Nb4 Rb6 34. Nxb6 Nxb6 35. Na6 1-0