BryanBradfo commited on
Commit
13f2c9d
·
verified ·
1 Parent(s): e4fa45d

Delete chess_tools.py

Browse files
Files changed (1) hide show
  1. chess_tools.py +0 -45
chess_tools.py DELETED
@@ -1,45 +0,0 @@
1
- import chess
2
- from collections import Counter
3
-
4
- def get_opening_name(board):
5
- """Détection basique d'ouverture basée sur les premiers coups"""
6
- # Pour une vraie détection, il faudrait une base de données,
7
- # mais pour le hackathon, on fait une approximation intelligente.
8
- fen = board.fen()
9
- if "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR" in fen: return "Ouverture du Pion Roi"
10
- if "rnbqkbnr/pppppppp/8/8/3P4/8/PPP1PPPP/RNBQKBNR" in fen: return "Ouverture du Pion Dame"
11
- if "rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR" in fen: return "Partie Espagnole ou Italienne (Début)"
12
- if "c5" in board.move_stack[0].uci() if board.move_stack else False: return "Défense Sicilienne"
13
- return "Jeu non classifié"
14
-
15
- def analyze_position(fen):
16
- board = chess.Board(fen)
17
-
18
- # 1. Matériel
19
- values = {chess.PAWN: 1, chess.KNIGHT: 3, chess.BISHOP: 3, chess.ROOK: 5, chess.QUEEN: 9}
20
- white_mat = sum(len(board.pieces(pt, chess.WHITE)) * val for pt, val in values.items())
21
- black_mat = sum(len(board.pieces(pt, chess.BLACK)) * val for pt, val in values.items())
22
- imbalance = white_mat - black_mat
23
-
24
- # 2. Sécurité du Roi (Check)
25
- in_check = board.is_check()
26
-
27
- # 3. Menaces immédiates (Attaques sur pièces majeures)
28
- threats = []
29
- if board.turn == chess.WHITE:
30
- # Est-ce que les blancs attaquent une pièce majeure noire ?
31
- for sq in chess.SQUARES:
32
- p = board.piece_at(sq)
33
- if p and p.color == chess.BLACK and p.piece_type in [chess.QUEEN, chess.ROOK]:
34
- if board.is_attacked_by(chess.WHITE, sq):
35
- threats.append(f"Attaque sur {chess.piece_name(p.piece_type)}")
36
-
37
- return {
38
- "fen": fen,
39
- "turn": "White" if board.turn == chess.WHITE else "Black",
40
- "material_imbalance": imbalance,
41
- "in_check": in_check,
42
- "is_game_over": board.is_game_over(),
43
- "opening": get_opening_name(board),
44
- "threats": list(set(threats))
45
- }