Skip to content

Commit d05e023

Browse files
committed
Added cloud analysis for chess positions
1 parent 1b000a4 commit d05e023

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

berserk/clients.py

+27
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'Teams',
2222
'Tournaments',
2323
'Users',
24+
'Analysis'
2425
]
2526

2627

@@ -74,6 +75,7 @@ class Client(BaseClient):
7475
- :class:`tournaments <berserk.clients.Tournaments>` - getting and
7576
creating tournaments
7677
- :class:`users <berserk.clients.Users>` - getting information about users
78+
- :class:`analysis <berserk.clients.Analysis>` - getting analysis of positions
7779
7880
:param session: request session, authenticated as needed
7981
:type session: :class:`requests.Session`
@@ -100,6 +102,7 @@ def __init__(self, session=None, base_url=None, pgn_as_default=False):
100102
self.broadcasts = Broadcasts(session, base_url)
101103
self.simuls = Simuls(session, base_url)
102104
self.studies = Studies(session, base_url)
105+
self.analysis = Analysis(session, base_url=base_url)
103106

104107

105108
class Account(BaseClient):
@@ -1118,3 +1121,27 @@ def export(self, study_id):
11181121
"""
11191122
path = f'/study/{study_id}.pgn'
11201123
return self._r.get(path, fmt=PGN, stream=True)
1124+
1125+
class Analysis(BaseClient):
1126+
"""Get analysis of chess positions."""
1127+
1128+
def evaluate_position(self, fen, multiPv=1, variant='standard'):
1129+
"""Get evaluation of position, if stored in the lichess database.
1130+
Up to 7 million positions stored.
1131+
1132+
:param str fen: the chess position to analyze
1133+
:param multPv: number of variations in the future
1134+
:param variant: the variant of the position
1135+
1136+
:return: the analysis of the queried position
1137+
with the fen, knodes, depth, and future variations
1138+
:rtype: dict"""
1139+
1140+
path = '/api/cloud-eval'
1141+
params = {
1142+
'fen': fen,
1143+
'multiPv': multiPv,
1144+
'variant': variant
1145+
}
1146+
return self._r.get(path, params=params)
1147+

0 commit comments

Comments
 (0)