Browse Source

import chess package

main
0x90.space 1 year ago
parent
commit
a236cff3c5
  1. 37
      blunderboard.go
  2. 3
      go.mod
  3. 3
      go.sum

37
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())
}

3
go.mod

@ -0,0 +1,3 @@
module git.0x90.space/0x90/blunderboard
require github.com/notnil/chess v1.5.0

3
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=
Loading…
Cancel
Save