Spaces:
Sleeping
Sleeping
Alexandre Gazola
commited on
Commit
·
7514a27
1
Parent(s):
6b2c1f8
trocando a api para a jogada do xadrez
Browse files- analyse_chess_position_tool.py +17 -15
analyse_chess_position_tool.py
CHANGED
@@ -18,22 +18,24 @@ def get_best_move(fen: str) -> str:
|
|
18 |
"multiPv": 1, # only top move
|
19 |
"syzygy": 5 # enable tablebase for 5-piece positions
|
20 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
if response.status_code != 200:
|
25 |
-
return f"API error: {response.status_code} - {response.text}"
|
26 |
-
|
27 |
-
data = response.json()
|
28 |
-
if not data.get("pvs"):
|
29 |
-
return "No best move found."
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
if "mate" in best_line or best_line.get("cp", 0) > 500:
|
37 |
-
return move
|
38 |
|
39 |
-
|
|
|
|
18 |
"multiPv": 1, # only top move
|
19 |
"syzygy": 5 # enable tablebase for 5-piece positions
|
20 |
}
|
21 |
+
|
22 |
+
url = "https://chess-api.com/v1"
|
23 |
+
payload = {
|
24 |
+
"fen": fen,
|
25 |
+
"depth": 1
|
26 |
+
}
|
27 |
|
28 |
+
print(f"Buscando melhor jogada em {CHESS_MOVE_API} - {payload}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
response = requests.post(url, json=payload)
|
31 |
+
if response.status_code == 200:
|
32 |
+
#print(f"Retorno melhor jogada --> {response.text}")
|
33 |
+
dados = response.json()
|
34 |
+
move_algebric_notation = dados.get("san")
|
35 |
+
move = dados.get("text")
|
36 |
+
print(f"Melhor jogada segundo chess-api.com -> {move}")
|
37 |
|
38 |
+
return move_algebric_notation
|
|
|
|
|
39 |
|
40 |
+
else:
|
41 |
+
raise Exception(f"Erro na requisição: {response.status_code}")
|