Skip to content

Commit

Permalink
Added cloud analysis for chess positions
Browse files Browse the repository at this point in the history
  • Loading branch information
kaustubhk334 committed Jan 3, 2021
1 parent 1b000a4 commit d05e023
Showing 1 changed file with 27 additions and 0 deletions.
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)

0 comments on commit d05e023

Please sign in to comment.