Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit 8264b2d

Browse files
author
Sławomir Kur
committed
pgn read init attempt
1 parent 95b09df commit 8264b2d

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

chess.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from string import ascii_letters, digits, ascii_lowercase
55

66
from src.exceptions import *
7+
from src.game_modes import human_vs_human, human_vs_cpu, cpu_vs_cpu
78
from src.helpers import color
89
from src.helpers.args import parse_args
910
from src.network import Network
10-
from src.game_modes import human_vs_human, human_vs_cpu, cpu_vs_cpu
11-
11+
import re
1212

1313
class Chess:
1414
def __init__(self, auto_show_board=False, colors=True, symbols=False):
@@ -936,6 +936,39 @@ def am_i_pated(self):
936936
return True
937937
return False
938938

939+
def load_pgn(self, pgn_path):
940+
self.new_game()
941+
942+
with open(pgn_path) as pgn_file:
943+
pgn_str = pgn_file.read()
944+
945+
moves_str = ''
946+
for line in pgn_str.split('\n'):
947+
if line.startswith('['):
948+
continue
949+
if not line:
950+
continue
951+
moves_str += line + ' '
952+
953+
regex = re.compile(r'([0-9]+).\s+([a-zA-Z0-9\-\+\\\/]+)\s+([a-zA-Z0-9\-\+\\\/]+)')
954+
data = regex.findall(moves_str)
955+
956+
move_list = []
957+
for move in data:
958+
move_list.append(move[1])
959+
move_list.append(move[2])
960+
961+
for move in move_list:
962+
print(move)
963+
self.find_move_from_pgn_notation(move)
964+
965+
966+
def find_move_from_pgn_notation(self, x):
967+
pass
968+
# if len(x) == 2 and x[0].islower() and x[1].isdigit():
969+
# for i in range(8):
970+
# if self.board[]
971+
939972
@staticmethod
940973
def chess_symbol(piece):
941974
if piece == 'K':

0 commit comments

Comments
 (0)