-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchess-move.py
30 lines (23 loc) · 977 Bytes
/
chess-move.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import chess
import chess.engine
import os
# Proje klasörü içerisindeki "stockfish" klasörü ve uygulama dosyası
stockfish_path = os.path.join(os.getcwd(), "stockfish", "stockfish.exe") # Uygulama isminin kontrol edilmesi gerekiyor.
def best_move_from_fen(fen):
try:
# Satranç tahtasının FEN kodu ile oluşturulması
board = chess.Board(fen)
except ValueError:
print("Hatalı FEN kodu yazdınız!")
return None
# Stockfish'in çalıştırılması
with chess.engine.SimpleEngine.popen_uci(stockfish_path) as engine:
# En iyi hamlenin hesaplanması
result = engine.play(board, chess.engine.Limit(time=5.0)) # 5 saniye analiz süresi
return result.move
# Örnek FEN kodu
fen_code = "r1bqkb1r/pppp1ppp/2n2n2/4p1N1/2B1P3/8/PPPP1PPP/RNBQK2R b KQkq - 5 4"
# Belirtilen FEN koduna göre en iyi hamle
best_move = best_move_from_fen(fen_code)
if best_move:
print("En iyi hamle:", best_move)