notnil / chess

chess package for go
MIT License
509 stars 127 forks source link

How do we set UCI options #72

Closed owenchak closed 2 years ago

owenchak commented 3 years ago

Hi, it appears that stockfish uses 1 thread by default. How would I set the UCI thread option?

I've tried manually changing engine.New as follows but it didn't make any difference

func New(path string, opts ...func(e *Engine)) (*Engine, error) {
    path, err := exec.LookPath(path)
    if err != nil {
        return nil, fmt.Errorf("uci: executable not found at path %s %w", path, err)
    }
    rIn, wIn := io.Pipe()
    rOut, wOut := io.Pipe()
    cmd := exec.Command(path)
    cmd.Stdin = rIn
    cmd.Stdout = wOut
    var options = make(map[string] Option)
    options["Threads"] = Option{
        Name: "Threads",
        Type:  OptionSpin,
        Default: "2",
        Min: "2",
        Max: "4",
        Vars: []string{},
    }
    e := &Engine{cmd: cmd, in: wIn, out: rOut, mu: &sync.RWMutex{}, logger: log.New(os.Stdout, "uci", log.LstdFlags), options: options}
    for _, opt := range opts {
        opt(e)
    }
    go e.cmd.Run()
    return e, nil
}
alex65536 commented 3 years ago

It seems that CmdSetOption does what you want:

e := engine.New(...)
e.Run(CmdSetOption{Name: "Threads", Value: "2"})
notnil commented 3 years ago

@owenchak does this solve your issue?