Jan-17-2026, 02:48 PM
hi,
my function :
Using split() rather than [4:68] resolves the issue.
Macos 26,2 anaconda python 3.13.5
best regards
my function :
def analyze_deviations(file_path):
deviations = []
with open(file_path, 'r') as f:
lines = [line.strip() for line in f if line.strip()]
# On parcourt le fichier deux par deux (Aller / Retour)
for i in range(0, len(lines) - 1, 2):
line1 = lines[i]
line2 = lines[i+1]
# Extraction de l'othellier (situé après le score de 3 char + 1 espace)
# Format : [Score(3)] [Espace] [Board(64)] [Espace] [Player] ...
board1 = line1[4:68]
board2 = line2[4:68]
empty1 = board1.count('-')
empty2 = board2.count('-')
# CAS SPÉCIAL : Si on voit deux plateaux de départ (50 vides)
if empty1 == 50 and empty2 == 50:
# Si les othelliers sont strictement identiques,
# c'est un match retour sans variation -> Coup 1
if board1 == board2:
deviations.append(1)
i += 2
else:
# Si les othelliers sont différents (ou si c'est deux "Aller" de suite)
# On applique ta convention du Coup 0
deviations.append(0)
i += 1
else:
# CAS GÉNÉRAL
deviations.append(50 - empty2 + 1)
i += 2
return deviationsmy file : extract-20 -------------O----*-O------*OO----*O**----OOO-----*------------- * D7C4B6F6B5F7D3B4A5D8F3A3E8F8E7C8G3G4F1A7B3E2G6G5H5H3A6A4H4H6B7H2D1A2H7H8G2C2G8A8G7B8C1H1B2G1D2A1E1B1 8 -------------O----**O-----**OO---***OO---***OO----**-O---------- O C2E2E1C1C8E8B4A5B3A4A3D2E7F3G4G3H4G1B2G5H5H6G6H3F1D1D8B8A2F8G7G2H1A1B1H8H2G8H7PAA7B7A8A6 24 --------------O----**O---***O------OO*------O--------O--------O- * F4E2F6G4G3F2H4H5G5H3H1D6G6E7G1D2C3E1C1H6D1F1H2B5C2A4H7B3A3A2C5B2C7D7A1B1C6G7H8C8A5A6F8E8D8B6A7B7B8A8 26 --------------O----**O---***O------OO*------O--------O--------O- * F6G5G3C3C5D2F4E2C6D6F2E7B3B6D7D8G6H5D1E1C1H3C2G4F1B5E8F8H1G7C7A4A3A2C8B8A5A6B7A8A7B1H2G1H4B2A1PAH7H6H8 -2 O--------O------OOO---*--O*OO*-----**-------*------------------- * F3C5D3E3E2D6C6F5B6G4D2C2B5F7F6C7A4A6D7A5F8D8E8E7C8G6C1F1D1E1F2B1H4G5A2G1H7G2H1H2H3H5H6G7A7A8G8B8B7H8 -28 O--------O------OOO---*--O*OO*-----**-------*------------------- * E3D6C6C5D3C7B5A4A6E7D7A5C8F5B6D2E2C2F3F1F7F2C1B1F6H3G2D1G5G4H4H1H2H5A2B7H6H7G6A7B8F8G8G7E8D8H8A8G1E1The file is perfectly formatted (no hidden characters).
Reading line 4 results in --------O------OOO-----OOO------------*------------------- which is correct. Reading line 5 results in O--------O------OOO-----OOO------------*------------------- which is incorrect.why ?
Using split() rather than [4:68] resolves the issue.
Macos 26,2 anaconda python 3.13.5
best regards
