Repository navigation
Expand file tree
/
Copy pathclean_puzzles.py
More file actions
74 lines (56 loc) · 2.3 KB
/
Copy pathclean_puzzles.py
File metadata and controls
74 lines (56 loc) · 2.3 KB
1
2
3
4
5
6
930B
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
""" clean/re-org puzzle collection """
import glob
import os
from typing import Optional
from sgf_wrapper import SGFReader
KANJI0 = '0'
KANJI0ORD = ord(KANJI0)
KANJI2ROMAN = str.maketrans(''.join([chr(KANJI0ORD + x) for x in range(10)]),
''.join([str(x) for x in range(10)]))
def replace_all_kanji_numbers(s: str):
return s.translate(KANJI2ROMAN)
def try_recode_puzzle_to_9x9(reader: SGFReader) -> Optional[str]:
""" try fit a puzzle on a 9x9 board
:return: None if impossible
"""
return None
def batch_check_puzzles(glob_pattern: str):
matches = sorted(glob.glob(glob_pattern))
print('Total %d puzzles' % len(matches))
for sgf_fname in matches:
basename = os.path.basename(sgf_fname)
reader = SGFReader.from_file_compatible(sgf_fname)
print(f'{basename} {reader.board_size()} komi={reader.komi()} RE={reader.result_str()}')
def test_unicode():
kanji1 = '1'
kanji2 = '2'
base0 = ord(KANJI0)
assert ord(kanji1) == base0 + 1
assert ord(kanji2) == base0 + 2
print(chr(base0 + 9))
# parens are fine
left_paren, right_paren = '(', ')'
assert left_paren == '('
def test_replace():
sgf_fname = '/Users/hyu/Downloads/go-puzzle9/Amigo no igo - 詰碁2023 - Life and Death/総合問題4級(3).sgf'
new_fname = replace_all_kanji_numbers(sgf_fname)
assert new_fname != sgf_fname
assert new_fname[:-12] == sgf_fname[:-12]
print(new_fname)
print(len(new_fname) - len(sgf_fname))
def test_rename_files():
""" replace Kanji numbers in filenames
"""
# sgf_fname = '/Users/hyu/Downloads/go-puzzle9/Amigo no igo - 詰碁2023 - Life and Death/総合問題9級.sgf'
sgf_prefix = '/Users/hyu/Downloads/go-puzzle9/Amigo no igo - 詰碁2023 - Life and Death/総合問題'
matches = glob.glob(f'{sgf_prefix}*.sgf')
for sgf_fname in matches:
new_fname = replace_all_kanji_numbers(sgf_fname)
os.rename(sgf_fname, new_fname)
def test_batch_check():
sgf_dir = '/Users/hyu/Downloads/go-puzzle9'
sgf_pattern = f'{sgf_dir}/Amigo no igo - 詰碁2023 - Life and Death/*'
sgf_pattern = f'{sgf_dir}/Beginning Shapes/*'
sgf_pattern = f'{sgf_dir}/easy 2-choice question*/*'
sgf_pattern = f'{sgf_dir}/How to Play Go +/*'
batch_check_puzzles(sgf_pattern)