py-stockfish / stockfish

Integrates the Stockfish chess engine with Python (Official fork)
https://py-stockfish.github.io/stockfish/
MIT License
30 stars 9 forks source link

Add include_info=True flag to .get_top_moves() #15

Closed knutole closed 1 year ago

knutole commented 1 year ago

In certain use-cases it is nice to get more information from .get_top_moves(), like WDL, selective depth, nodes, etc.

One use-case for this is when evaluating full games. If you want both top moves for n lines, and the WDL, you'd have to run the evaluation multiple times. Also, there is currently no way of getting info like nodes, time, nps, etc.

# unchanged 
moves = stockfish.get_top_moves(2)
print(moves)
# [
#   {   
#     'Centipawn': None,
#     'Mate': 1,
#     'Move': 'e1e8'
#   },
#   {
#     'Centipawn': None,
#     'Mate': 2,
#     'Move': 'c8e8'
#   }
# ]

# unchanged
moves = stockfish.get_top_moves(2, include_info=False)
print(moves)
# [
#   {   
#     'Centipawn': None,
#     'Mate': 1,
#     'Move': 'e1e8'
#   },
#   {
#     'Centipawn': None,
#     'Mate': 2,
#     'Move': 'c8e8'
#   }
# ]

# returns more info
moves = stockfish.get_top_moves(2, include_info=True)
print(moves)
# [
#   {   
#     'Centipawn': None,
#     'Mate': 1,
#     'Move': 'e1e8',
#     'MultiPVLine': '1',
#     'N/s': '10255014',
#     'Nodes': '5096742',
#     'SelectiveDepth': '2',
#     'Time': '497',
#     'WDL': '1000 0 0'
#   },
#   {
#     'Centipawn': None,
#     'Mate': 2,
#     'Move': 'c8e8',
#     'MultiPVLine': '2',
#     'N/s': '10255014',
#     'Nodes': '5096742',
#     'SelectiveDepth': '4',
#     'Time': '497',
#     'WDL': '1000 0 0'
#   }
# ]

Example use-case: https://github.com/knutole/catchfish 🐳

github-actions[bot] commented 1 year ago

Coverage report

The coverage rate went from 93.35% to 95.89% :arrow_up: The branch rate is 91%.

100% of new lines are covered.

Diff Coverage details (click to unfold) ### stockfish/models.py `100%` of new lines are covered (`95.89%` of the complete file).
knutole commented 1 year ago

The flag include_info could be renamed to verbose.

kieferro commented 1 year ago

The flag include_info could be renamed to verbose.

I think both names would make sense here. It's your call

knutole commented 1 year ago

The flag include_info could be renamed to verbose.

I think both names would make sense here. It's your call

For backwards compatibility, I guess keeping include_info is better.

knutole commented 1 year ago

Please see https://github.com/py-stockfish/stockfish/pull/16/