From 039bb049346e2d2967120db25e378a8db4cc4e8d Mon Sep 17 00:00:00 2001 From: "0x90.space" Date: Sat, 28 Aug 2021 21:34:07 +0100 Subject: [PATCH] read real game from pgn --- blunderboard.go | 24 +++++++++++++++++++----- spongeboyahoy_vs_tomlx.pgn | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 spongeboyahoy_vs_tomlx.pgn diff --git a/blunderboard.go b/blunderboard.go index d637844..964f8ac 100644 --- a/blunderboard.go +++ b/blunderboard.go @@ -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 { diff --git a/spongeboyahoy_vs_tomlx.pgn b/spongeboyahoy_vs_tomlx.pgn new file mode 100644 index 0000000..d645415 --- /dev/null +++ b/spongeboyahoy_vs_tomlx.pgn @@ -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 +