• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

shogi-server source


Commit MetaInfo

Revisãoa0bc16bf2c5d10b71ee7379dbb26bc8e7104ee34 (tree)
Hora2020-09-06 11:58:23
AutorTadaoYamaoka <tadaoyamaoka@gmai...>
CommiterTadaoYamaoka

Mensagem de Log

kifファイルを分割して出力

Mudança Sumário

Diff

--- a/utils/log_to_kifu.py
+++ b/utils/log_to_kifu.py
@@ -1,5 +1,6 @@
11 import shogi
22 from shogi import CSA
3+import os
34 import math
45 import re
56 import datetime
@@ -7,7 +8,7 @@ import argparse
78
89 parser = argparse.ArgumentParser()
910 parser.add_argument('log')
10-parser.add_argument('kifu')
11+parser.add_argument('--out_dir', default='.')
1112 args = parser.parse_args()
1213
1314 KIFU_TO_SQUARE_NAMES = [
@@ -177,8 +178,6 @@ ptn_info = re.compile(r'^ +(info .*score .*)$')
177178 ptn_move = re.compile(r'^ +([+-]\d{4}..),T(\d+)$')
178179 ptn_resign = re.compile(r'^ +%TORYO,T(\d+)$')
179180
180-kifu = open(args.kifu, 'w')
181-
182181 with open(args.log) as f:
183182 for line in f.readlines():
184183 # 時刻
@@ -186,6 +185,8 @@ with open(args.log) as f:
186185 if m:
187186 starttime = datetime.datetime.strptime(m.groups()[0], '%Y-%m-%dT%H:%M:%S')
188187 continue
188+ # JST
189+ starttime += datetime.timedelta(hours=9)
189190
190191 # Name
191192 m = ptn_name1.search(line)
@@ -199,7 +200,11 @@ with open(args.log) as f:
199200
200201 # 開始
201202 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))
203208 board = shogi.Board()
204209 sec_sum = 0
205210 info = None
@@ -229,4 +234,5 @@ with open(args.log) as f:
229234 sec = int(m.groups()[0])
230235 sec_sum += sec
231236 kifu_line(kifu, board, 'resign', sec, sec_sum, info)
237+ kifu.close()
232238 continue