Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cloud analysis for chess positions #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions berserk/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'Teams',
'Tournaments',
'Users',
'Analysis'
]


Expand Down Expand Up @@ -74,6 +75,7 @@ class Client(BaseClient):
- :class:`tournaments <berserk.clients.Tournaments>` - getting and
creating tournaments
- :class:`users <berserk.clients.Users>` - getting information about users
- :class:`analysis <berserk.clients.Analysis>` - getting analysis of positions
:param session: request session, authenticated as needed
:type session: :class:`requests.Session`
Expand All @@ -100,6 +102,7 @@ def __init__(self, session=None, base_url=None, pgn_as_default=False):
self.broadcasts = Broadcasts(session, base_url)
self.simuls = Simuls(session, base_url)
self.studies = Studies(session, base_url)
self.analysis = Analysis(session, base_url=base_url)


class Account(BaseClient):
Expand Down Expand Up @@ -1118,3 +1121,27 @@ def export(self, study_id):
"""
path = f'/study/{study_id}.pgn'
return self._r.get(path, fmt=PGN, stream=True)

class Analysis(BaseClient):
"""Get analysis of chess positions."""

def evaluate_position(self, fen, multiPv=1, variant='standard'):
"""Get evaluation of position, if stored in the lichess database.
Up to 7 million positions stored.
:param str fen: the chess position to analyze
:param multPv: number of variations in the future
:param variant: the variant of the position
:return: the analysis of the queried position
with the fen, knodes, depth, and future variations
:rtype: dict"""

path = '/api/cloud-eval'
params = {
'fen': fen,
'multiPv': multiPv,
'variant': variant
}
return self._r.get(path, params=params)