Class: Stockshark::Engine
- Inherits:
-
Object
- Object
- Stockshark::Engine
- Defined in:
- lib/stockshark/engine.rb
Overview
The public façade for talking to a UCI engine — the only class most callers should ever need to touch. Hides process management (Process) and protocol parsing (UciProtocol) entirely: callers only ever see "give me a FEN and a depth/movetime, get back an evaluation."
Defined Under Namespace
Classes: AnalysisResult, Line
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #analyze(fen:, depth: nil, movetime_ms: nil, multipv: 1) ⇒ Object
-
#initialize(configuration = Stockshark::Configuration.new, process: nil) ⇒ Engine
constructor
A new instance of Engine.
-
#quit ⇒ Object
Safe to call more than once, and safe to call even if the engine was never fully brought up (e.g. handshake itself failed).
Constructor Details
#initialize(configuration = Stockshark::Configuration.new, process: nil) ⇒ Engine
Returns a new instance of Engine.
21 22 23 24 25 26 |
# File 'lib/stockshark/engine.rb', line 21 def initialize(configuration = Stockshark::Configuration.new, process: nil) @configuration = configuration @process = process || Stockshark::Process.new(configuration.path) @multipv = 1 handshake end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/stockshark/engine.rb', line 19 def name @name end |
Instance Method Details
#analyze(fen:, depth: nil, movetime_ms: nil, multipv: 1) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/stockshark/engine.rb', line 28 def analyze(fen:, depth: nil, movetime_ms: nil, multipv: 1) raise ArgumentError, "must give depth or movetime_ms" unless depth || movetime_ms set_multipv(multipv) send_line("position fen #{fen}") send_line(depth ? "go depth #{depth}" : "go movetime #{movetime_ms}") collect_result(search_timeout(movetime_ms)) end |
#quit ⇒ Object
Safe to call more than once, and safe to call even if the engine was never fully brought up (e.g. handshake itself failed).
40 41 42 |
# File 'lib/stockshark/engine.rb', line 40 def quit @process.stop end |