From a236cff3c57011b7950d2ac0f701befd3893e315 Mon Sep 17 00:00:00 2001 From: "0x90.space" Date: Wed, 4 Aug 2021 02:00:55 +0100 Subject: [PATCH] import chess package --- blunderboard.go | 37 +++++++++++++++++++++++++++++++++++++ go.mod | 3 +++ go.sum | 3 +++ 3 files changed, 43 insertions(+) create mode 100644 blunderboard.go create mode 100644 go.mod create mode 100644 go.sum diff --git a/blunderboard.go b/blunderboard.go new file mode 100644 index 0000000..4a83f0c --- /dev/null +++ b/blunderboard.go @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "github.com/notnil/chess" + "github.com/notnil/chess/uci" + "math/rand" + "time" +) + +func main() { + engine, err := uci.New("stockfish") + if err != nil { + panic(err) + } + defer engine.Close() + + if err := engine.Run(uci.CmdUCI, uci.CmdIsReady, uci.CmdUCINewGame); err != nil { + 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 { + panic(err) + } + game.Move(engine.SearchResults().BestMove) + } + fmt.Println(game.String()) + fmt.Println(game.Position().Board().Draw()) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fb4d781 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.0x90.space/0x90/blunderboard + +require github.com/notnil/chess v1.5.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3256ec6 --- /dev/null +++ b/go.sum @@ -0,0 +1,3 @@ +github.com/ajstarks/svgo v0.0.0-20200320125537-f189e35d30ca/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= +github.com/notnil/chess v1.5.0 h1:BcdmSGqZYhoqHsAqNpVTtPwRMOA4Sj8iZY1ZuPW4Umg= +github.com/notnil/chess v1.5.0/go.mod h1:cRuJUIBFq9Xki05TWHJxHYkC+fFpq45IWwk94DdlCrA=