depth.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import subprocess
  2. import time
  3. def do_timing():
  4. bis = subprocess.Popen(['cargo', 'run', '--release'],
  5. stdout=subprocess.PIPE,
  6. stdin=subprocess.PIPE)
  7. bis.stdin.write(b'isready\n')
  8. bis.stdin.flush()
  9. for line in bis.stdout:
  10. if line[:7] == b'readyok':
  11. break
  12. bis.stdin.write(b'position fen r3kb1r/pppqn1p1/2n4p/5b2/3PQ3/5NP1/PPP2PBP/R1B2RK1 w kq - 1 13\n')
  13. bis.stdin.write(b'go depth 8\n')
  14. bis.stdin.flush()
  15. start = time.time()
  16. for line in bis.stdout:
  17. print("line: " + str(line))
  18. if line[:8] == b'bestmove':
  19. break
  20. bis.stdin.write(b'position fen 3r4/2p2r1k/p5p1/Pp5p/3BRP2/bqP4P/6PK/2Q1R3 w - - 6 40\n')
  21. bis.stdin.write(b'go depth 7\n')
  22. bis.stdin.flush()
  23. for line in bis.stdout:
  24. print("line: " + str(line))
  25. if line[:8] == b'bestmove':
  26. break
  27. bis.stdin.write(b'position fen 8/6k1/7N/5p2/1R1P1B1P/2P5/4PP1P/6K1 w - - 0 52\n')
  28. bis.stdin.write(b'go depth 9\n')
  29. bis.stdin.flush()
  30. for line in bis.stdout:
  31. print("line: " + str(line))
  32. if line[:8] == b'bestmove':
  33. break
  34. end = time.time()
  35. return end - start
  36. measure = 0
  37. nMes = 3
  38. for i in range(0, nMes):
  39. measure = measure + do_timing()
  40. measure = measure / nMes
  41. print(f"finished in {round(measure, 3)} s")