stockfish 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -5
- data/bin/console +1 -0
- data/lib/stockfish/analysis_parser.rb +1 -1
- data/lib/stockfish/engine.rb +6 -2
- data/lib/stockfish/version.rb +1 -1
- data/script/bench.rb +93 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a5aa5006827d6d521edcfbbb7bc60bc13e512fc5
|
|
4
|
+
data.tar.gz: 7bcef634f4c7c5f1cfec59be4c17870b4bd50df8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d51fd8c10cb5a29f3b6d28db9fa7f9a6ba34af4d7f444d502e641ee05da85e821731f68f4307ac25fe9bd6e305fd740f927e4a031e6ce1d5568da83a8bbc1d7f
|
|
7
|
+
data.tar.gz: fcd7fb365b4bb4b9c545a568d3c227f178d119b2f3ba48bc31d4fec8c6bcba5d993dc2328036fc7b691252fbbb02421f8f0de05d74a42997022c13e0cec9e608
|
data/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A ruby client for the [Stockfish](https://stockfishchess.org/) chess engine
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
## Installation
|
|
6
7
|
|
|
7
8
|
```
|
|
@@ -14,6 +15,7 @@ Or add it to your application's Gemfile and install via bundler
|
|
|
14
15
|
gem 'stockfish'
|
|
15
16
|
```
|
|
16
17
|
|
|
18
|
+
|
|
17
19
|
## Analyzing positions
|
|
18
20
|
|
|
19
21
|
Load a position in [FEN](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation) notation that you want to analyze
|
|
@@ -28,24 +30,37 @@ Set the search depth (in number of half-moves) you want to use
|
|
|
28
30
|
Stockfish.analyze fen, { :depth => 12 }
|
|
29
31
|
```
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
Look at multiple variations by setting a multipv option
|
|
32
34
|
|
|
33
35
|
```ruby
|
|
34
|
-
Stockfish.analyze fen, { :depth =>
|
|
36
|
+
Stockfish.analyze fen, { :depth => 12, :multipv => 3 }
|
|
35
37
|
```
|
|
36
38
|
|
|
39
|
+
|
|
40
|
+
## Communicating with the engine
|
|
41
|
+
|
|
42
|
+
You can also send [UCI](https://en.wikipedia.org/wiki/Universal_Chess_Interface) commands to Stockfish directly
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
engine = Stockfish::Engine.new
|
|
46
|
+
engine.execute "position fen q3r3/3r4/p2p2p1/1p2p1b1/8/P6k/1PP1Q2P/4BRK1 b - - 8 36"
|
|
47
|
+
engine.execute "setoption name MultiPV value 3"
|
|
48
|
+
engine.execute "go depth 10"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
|
|
37
52
|
## Requirements
|
|
38
53
|
|
|
39
|
-
Stockfish 6+ must be installed and available in your
|
|
54
|
+
Stockfish 6+ must be installed and available in your `$PATH`
|
|
40
55
|
|
|
41
56
|
```bash
|
|
42
57
|
$ which stockfish
|
|
43
58
|
```
|
|
44
59
|
|
|
45
|
-
|
|
60
|
+
Or you can load a Stockfish binary directly
|
|
46
61
|
|
|
47
62
|
```ruby
|
|
48
63
|
engine = Stockfish::Engine.new("/usr/local/bin/stockfish")
|
|
49
64
|
engine.multipv(3)
|
|
50
|
-
engine.analyze fen, { :depth =>
|
|
65
|
+
engine.analyze fen, { :depth => 12 }
|
|
51
66
|
```
|
data/bin/console
CHANGED
|
@@ -7,6 +7,7 @@ require 'stockfish'
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
engine = Stockfish::Engine.new
|
|
10
|
+
puts engine.version
|
|
10
11
|
|
|
11
12
|
# puts engine.analyze "rqb2rk1/1p3p2/p1nb1n1p/2pp4/2P4Q/N2P1N2/PP2BPPP/R4RK1 w - - 1 15", { :nodes => 100000 }
|
|
12
13
|
# puts engine.analyze "2r2rk1/p2q1pbp/4b1p1/1p1p4/3P4/1Q2B1P1/PP3PBP/2RR2K1 w - b6 1 17", { :movetime => 2000 }
|
|
@@ -68,7 +68,7 @@ module Stockfish
|
|
|
68
68
|
:sequence => sequence[:moves].split(/\s+/),
|
|
69
69
|
:depth => analysis[:depth].to_i,
|
|
70
70
|
}
|
|
71
|
-
variation[:multipv] = analysis[:multipv]
|
|
71
|
+
variation[:multipv] = analysis[:multipv] ? analysis[:multipv].to_i : 1
|
|
72
72
|
variation
|
|
73
73
|
end
|
|
74
74
|
|
data/lib/stockfish/engine.rb
CHANGED
|
@@ -17,13 +17,17 @@ module Stockfish
|
|
|
17
17
|
@stdin, @stdout, @stderr, @wait_threads = Open3.popen3(bin_path)
|
|
18
18
|
@pid = @wait_threads[:pid]
|
|
19
19
|
@version = @stdout.readline.strip
|
|
20
|
-
|
|
20
|
+
unless @version =~ /^Stockfish/
|
|
21
|
+
raise InvalidBinary.new("Not a valid Stockfish binary!")
|
|
22
|
+
end
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
def execute(str)
|
|
24
26
|
command = str.split(" ")[0]
|
|
25
27
|
@stdin.puts str
|
|
26
|
-
|
|
28
|
+
unless COMMANDS.include?(command)
|
|
29
|
+
raise InvalidCommand.new(@stdout.readline.strip)
|
|
30
|
+
end
|
|
27
31
|
output = ""
|
|
28
32
|
case command
|
|
29
33
|
when "uci"
|
data/lib/stockfish/version.rb
CHANGED
data/script/bench.rb
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
$:.unshift "./lib"
|
|
2
|
+
require 'stockfish'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def print_elapsed(elapsed)
|
|
6
|
+
puts "Time elapsed #{"%0.3f" % elapsed}s"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def time_elapsed(&block)
|
|
10
|
+
t0 = Time.now
|
|
11
|
+
block.call
|
|
12
|
+
elapsed = Time.now - t0
|
|
13
|
+
print_elapsed elapsed
|
|
14
|
+
elapsed
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
t = 0
|
|
19
|
+
|
|
20
|
+
t += time_elapsed do
|
|
21
|
+
fen = "2rq1rk1/1b1nppbp/pp3np1/2ppN3/P2P1B2/2P1P2P/1P1NBPP1/R2Q1RK1 w - - 2 12"
|
|
22
|
+
Stockfish::Engine.new.analyze fen, { :depth => 20 }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
t += time_elapsed do
|
|
26
|
+
fen = "2r2rk1/5q1p/pp3ppb/P2b4/3Pp3/1NP4P/2Q2PPB/R3R1K1 w - - 1 27"
|
|
27
|
+
Stockfish::Engine.new.analyze fen, { :depth => 20 }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
t += time_elapsed do
|
|
31
|
+
fen = "3q1rk1/1b1rbppp/p2ppn2/1p6/3BPP2/P1NB2Q1/1PP3PP/4RR1K w - - 5 17"
|
|
32
|
+
Stockfish::Engine.new.analyze fen, { :depth => 16 }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
t += time_elapsed do
|
|
36
|
+
fen = "3qr1k1/1b1rbp2/p2p1np1/1p2p3/4P3/P1NBB2Q/1PP3PP/4RR1K w - - 0 21"
|
|
37
|
+
Stockfish::Engine.new.analyze fen, { :depth => 16 }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
t += time_elapsed do
|
|
41
|
+
fen = "r2qk2r/ppp1p1bp/5np1/3p2B1/6b1/3BQN2/PPP2PPP/R4RK1 b kq - 0 14"
|
|
42
|
+
Stockfish::Engine.new.analyze fen, { :depth => 14 }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
t += time_elapsed do
|
|
46
|
+
fen = "rnbqk2r/ppppppbp/6p1/2n1P3/2BP4/5N2/PPP2PPP/RNBQK2R b KQkq - 0 6"
|
|
47
|
+
Stockfish::Engine.new.analyze fen, { :depth => 14 }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
t += time_elapsed do
|
|
51
|
+
fen = "3qr3/1b1r1Q2/p2p1bp1/1p2p3/4k3/P3B3/1PP3PP/4R2K w - - 6 29"
|
|
52
|
+
Stockfish::Engine.new.analyze fen, { :depth => 12 }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
t += time_elapsed do
|
|
56
|
+
fen = "r1bq1rk1/ppp1n1b1/3p1n1p/1PP1ppp1/8/2NP1NP1/P2BPPBP/1R1Q1RK1 b - - 0 12"
|
|
57
|
+
Stockfish::Engine.new.analyze fen, { :depth => 12 }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
t += time_elapsed do
|
|
61
|
+
fen = "3q1rk1/1p4b1/r2pbnnp/4p3/4P1p1/2NPBpP1/P2Q1P1P/1R2NRKB b - - 3 20"
|
|
62
|
+
Stockfish::Engine.new.analyze fen, { :depth => 10 }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
t += time_elapsed do
|
|
66
|
+
fen = "8/5bbk/6np/r2np3/6p1/P2PBpPP/2N2P2/1N3RKB b - - 0 28"
|
|
67
|
+
Stockfish::Engine.new.analyze fen, { :depth => 10 }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
t += time_elapsed do
|
|
71
|
+
fen = "2k2r2/3bb1p1/pBqpp3/Pp5p/4P1n1/2NB4/1PP1Q1PP/R6K b - - 11 25"
|
|
72
|
+
Stockfish::Engine.new.analyze fen, { :depth => 16, :multipv => 3 }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
t += time_elapsed do
|
|
76
|
+
fen = "2k4r/3b2p1/p4b2/Pp1pq2p/6n1/2PB4/NP2Q1PP/5RBK w - - 1 31"
|
|
77
|
+
Stockfish::Engine.new.analyze fen, { :depth => 16, :multipv => 3 }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
t += time_elapsed do
|
|
81
|
+
fen = "8/5bbk/r2p1nnp/q3p3/4P1p1/P1NPBpP1/2NQ1P1P/5RKB b - - 0 24"
|
|
82
|
+
Stockfish::Engine.new.analyze fen, { :depth => 12, :multipv => 3 }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
t += time_elapsed do
|
|
86
|
+
fen = "8/8/4N2k/4n2p/6p1/r4pPP/4bP2/4R1KB w - - 8 39"
|
|
87
|
+
Stockfish::Engine.new.analyze fen, { :depth => 12, :multipv => 3 }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
puts
|
|
92
|
+
puts "Total time elapsed"
|
|
93
|
+
print_elapsed(t)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stockfish
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Linmiao Xu
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-01-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -69,6 +69,7 @@ files:
|
|
|
69
69
|
- lib/stockfish/engine.rb
|
|
70
70
|
- lib/stockfish/version.rb
|
|
71
71
|
- ruby-stockfish.gemspec
|
|
72
|
+
- script/bench.rb
|
|
72
73
|
- test/analysis_parser_test.rb
|
|
73
74
|
- test/engine_test.rb
|
|
74
75
|
- test/fixtures/analysis_outputs/black_loses_in_3.txt
|