Alexandre Gazola commited on
Commit
7514a27
·
1 Parent(s): 6b2c1f8

trocando a api para a jogada do xadrez

Browse files
Files changed (1) hide show
  1. 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
- response = requests.get(url, params=params)
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
- best_line = data["pvs"][0]
32
- score = best_line["cp"] if "cp" in best_line else f"Mate in {best_line.get('mate')}"
33
- move = best_line["moves"].split()[0]
 
 
 
 
34
 
35
- # Optional: threshold to define a "guaranteed win"
36
- if "mate" in best_line or best_line.get("cp", 0) > 500:
37
- return move
38
 
39
- return f"No clearly winning move. Best suggestion: {move} (score: {score})"
 
 
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}")