|
4 | 4 | from string import ascii_letters, digits, ascii_lowercase |
5 | 5 |
|
6 | 6 | from src.exceptions import * |
| 7 | +from src.game_modes import human_vs_human, human_vs_cpu, cpu_vs_cpu |
7 | 8 | from src.helpers import color |
8 | 9 | from src.helpers.args import parse_args |
9 | 10 | from src.network import Network |
10 | | -from src.game_modes import human_vs_human, human_vs_cpu, cpu_vs_cpu |
11 | | - |
| 11 | +import re |
12 | 12 |
|
13 | 13 | class Chess: |
14 | 14 | def __init__(self, auto_show_board=False, colors=True, symbols=False): |
@@ -936,6 +936,39 @@ def am_i_pated(self): |
936 | 936 | return True |
937 | 937 | return False |
938 | 938 |
|
| 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 | + |
939 | 972 | @staticmethod |
940 | 973 | def chess_symbol(piece): |
941 | 974 | if piece == 'K': |
|
0 commit comments