shogi-server source
Revisão | a0bc16bf2c5d10b71ee7379dbb26bc8e7104ee34 (tree) |
---|---|
Hora | 2020-09-06 11:58:23 |
Autor | TadaoYamaoka <tadaoyamaoka@gmai...> |
Commiter | TadaoYamaoka |
kifファイルを分割して出力
@@ -1,5 +1,6 @@ | ||
1 | 1 | import shogi |
2 | 2 | from shogi import CSA |
3 | +import os | |
3 | 4 | import math |
4 | 5 | import re |
5 | 6 | import datetime |
@@ -7,7 +8,7 @@ import argparse | ||
7 | 8 | |
8 | 9 | parser = argparse.ArgumentParser() |
9 | 10 | parser.add_argument('log') |
10 | -parser.add_argument('kifu') | |
11 | +parser.add_argument('--out_dir', default='.') | |
11 | 12 | args = parser.parse_args() |
12 | 13 | |
13 | 14 | KIFU_TO_SQUARE_NAMES = [ |
@@ -177,8 +178,6 @@ ptn_info = re.compile(r'^ +(info .*score .*)$') | ||
177 | 178 | ptn_move = re.compile(r'^ +([+-]\d{4}..),T(\d+)$') |
178 | 179 | ptn_resign = re.compile(r'^ +%TORYO,T(\d+)$') |
179 | 180 | |
180 | -kifu = open(args.kifu, 'w') | |
181 | - | |
182 | 181 | with open(args.log) as f: |
183 | 182 | for line in f.readlines(): |
184 | 183 | # 時刻 |
@@ -186,6 +185,8 @@ with open(args.log) as f: | ||
186 | 185 | if m: |
187 | 186 | starttime = datetime.datetime.strptime(m.groups()[0], '%Y-%m-%dT%H:%M:%S') |
188 | 187 | continue |
188 | + # JST | |
189 | + starttime += datetime.timedelta(hours=9) | |
189 | 190 | |
190 | 191 | # Name |
191 | 192 | m = ptn_name1.search(line) |
@@ -199,7 +200,11 @@ with open(args.log) as f: | ||
199 | 200 | |
200 | 201 | # 開始 |
201 | 202 | if ptn_newgame.search(line): |
202 | - kifu_header(kifu, starttime + datetime.timedelta(hours=9), (name1, name2)) | |
203 | + # kif open | |
204 | + filename = starttime.strftime('%Y%m%d_%H%M%S') + '_' + name1 + '_vs_' + name2 + '.kif' | |
205 | + kifu = open(os.path.join(args.out_dir, filename), 'w') | |
206 | + | |
207 | + kifu_header(kifu, starttime, (name1, name2)) | |
203 | 208 | board = shogi.Board() |
204 | 209 | sec_sum = 0 |
205 | 210 | info = None |
@@ -229,4 +234,5 @@ with open(args.log) as f: | ||
229 | 234 | sec = int(m.groups()[0]) |
230 | 235 | sec_sum += sec |
231 | 236 | kifu_line(kifu, board, 'resign', sec, sec_sum, info) |
237 | + kifu.close() | |
232 | 238 | continue |