forked from niklasf/python-chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.py
More file actions
53 lines (38 loc) · 1.24 KB
/
engine.py
File metadata and controls
53 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import asyncio
import logging
import chess.engine
from pythonfuzz.main import PythonFuzz
logging.getLogger("chess.engine").setLevel(logging.CRITICAL)
@PythonFuzz
def fuzz(buf):
lines = buf.split(b"!")
class FuzzTransport:
def __init__(self, protocol):
self.protocol = protocol
self.protocol.connection_made(self)
def get_pipe_transport(self, fd):
assert fd == 0, f"expected 0 for stdin, got {fd}"
return self
def write(self, data):
if lines:
self.protocol.pipe_data_received(1, lines.pop(0))
def get_pid(self) -> int:
return id(self)
def get_returncode(self):
return 0
async def main():
protocol = chess.engine.UciProtocol()
transport = FuzzTransport(protocol)
await asyncio.wait_for(protocol.initialize(), 0.1)
await asyncio.wait_for(protocol.ping(), 0.1)
await asyncio.wait_for(protocol.analysis(chess.Board(), chess.engine.Limit(nodes=1)), 0.1)
try:
asyncio.run(main())
except asyncio.TimeoutError:
pass
except UnicodeDecodeError:
pass
except chess.engine.EngineError:
pass
if __name__ == "__main__":
fuzz()