jkf 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.dir-locals.el +4 -0
- data/.github/workflows/release.yaml +31 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +0 -10
- data/LICENSE.txt +1 -0
- data/README.md +8 -4
- data/jkf.gemspec +5 -3
- data/lib/jkf/converter/base.rb +1 -1
- data/lib/jkf/converter/csa.rb +28 -31
- data/lib/jkf/converter/ki2.rb +13 -13
- data/lib/jkf/converter/kif.rb +25 -30
- data/lib/jkf/converter/kifuable.rb +24 -24
- data/lib/jkf/parser/base.rb +1 -1
- data/lib/jkf/parser/csa.rb +281 -286
- data/lib/jkf/parser/ki2.rb +3 -2
- data/lib/jkf/parser/kif.rb +3 -6
- data/lib/jkf/parser/kifuable.rb +2 -2
- data/lib/jkf/version.rb +1 -1
- data/lib/jkf.rb +1 -0
- data/manifest.scm +33 -93
- metadata +22 -16
- data/.github/workflows/ci.yml +0 -16
- data/.hound.yml +0 -3
- data/.rubocop.yml +0 -75
- data/.rubocop_todo.yml +0 -7
- data/Guardfile +0 -27
- data/bin/console +0 -15
- data/bin/setup +0 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e28e629f7c141b7493f9a9e978f6339b8e5730b9fc1539ce7617fe3847e96da6
|
|
4
|
+
data.tar.gz: 16766fef773477ba942d1832e1d40b94328b4006177e8871c15874133688d059
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9540ce1699ffa3ca96b1e56ed58fd1b9495b084e61d2c548896f689f46ad50d169cf56f775b9091ab7b968d0541b29f2f6f4934bf48e62d2bcba70a274c688b6
|
|
7
|
+
data.tar.gz: 2fd77c3f1183380b7819d7946c1b4cd6b897b089e5714fa7ca8f50da9205cce3c4493b1fecca359b84b9213c123a8a49a198869544c45350afb5588b6205673e
|
data/.dir-locals.el
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# https://guides.rubygems.org/trusted-publishing/releasing-gems/
|
|
2
|
+
name: Release
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- '*'
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
jobs:
|
|
9
|
+
push:
|
|
10
|
+
name: Push gem to RubyGems.org
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
|
|
15
|
+
contents: write # IMPORTANT: this permission is required for `rake release` to push the release tag
|
|
16
|
+
|
|
17
|
+
environment: release
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
# Set up
|
|
21
|
+
- uses: actions/checkout@v6
|
|
22
|
+
with:
|
|
23
|
+
persist-credentials: false
|
|
24
|
+
- name: Set up Ruby
|
|
25
|
+
uses: ruby/setup-ruby@v1
|
|
26
|
+
with:
|
|
27
|
+
bundler-cache: true
|
|
28
|
+
ruby-version: ruby
|
|
29
|
+
|
|
30
|
+
# Release
|
|
31
|
+
- uses: rubygems/release-gem@v1
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## 0.5.4 - 2026-05-02
|
|
11
|
+
|
|
12
|
+
Revert project links.
|
|
13
|
+
Enable Trusted Publishing.
|
|
14
|
+
|
|
15
|
+
## 0.5.3 - 2025-07-21
|
|
16
|
+
|
|
17
|
+
Update project links.
|
|
18
|
+
|
|
10
19
|
## 0.5.2 - 2024-10-26
|
|
11
20
|
|
|
12
21
|
This is a maintenance release.
|
data/Gemfile
CHANGED
|
@@ -2,21 +2,11 @@ source 'https://rubygems.org'
|
|
|
2
2
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
|
-
gem 'rake'
|
|
6
|
-
|
|
7
5
|
group :development do
|
|
8
|
-
gem 'redcarpet'
|
|
9
6
|
gem 'yard'
|
|
10
|
-
|
|
11
|
-
gem 'guard-rubocop'
|
|
12
|
-
gem 'rubocop', '~> 1.63'
|
|
13
|
-
gem 'rubocop-performance'
|
|
14
|
-
gem 'rubocop-rake', '~> 0.6.0'
|
|
15
|
-
gem 'rubocop-rspec', '~> 3.1'
|
|
16
7
|
end
|
|
17
8
|
|
|
18
9
|
group :test do
|
|
19
|
-
gem 'guard-rspec'
|
|
20
10
|
gem 'rspec', '~> 3.0'
|
|
21
11
|
gem 'simplecov'
|
|
22
12
|
end
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# jkf gem
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/rb/jkf) [](https://travis-ci.org/iyuuya/jkf) [](https://github.com/iyuuya/jkf/actions/workflows/ci.yml)
|
|
4
|
-
|
|
5
3
|
jkf gemは[JSON棋譜フォーマット (JKF)][jkf]をRubyに移植したものです。
|
|
6
4
|
柿木形式([棋譜ファイル KIF 形式][kakinoki]、KI2)、[CSA標準棋譜ファイル形式][csa]の構文解析とJKFへの変換、JKFからKIF, KI2, CSAへの変換に対応しています。
|
|
7
5
|
|
|
@@ -55,9 +53,9 @@ csa = csa_converter.convert(jkf) #=> String
|
|
|
55
53
|
|
|
56
54
|
## 貢献
|
|
57
55
|
|
|
58
|
-
バグレポートやプルリクエストは[
|
|
56
|
+
バグレポートやプルリクエストは[リポジトリ][repo]でよろしくお願いします。
|
|
59
57
|
|
|
60
|
-
[repo]: https://github.com/
|
|
58
|
+
[repo]: https://github.com/gemmaro/jkf
|
|
61
59
|
|
|
62
60
|
Guixで開発されている場合は`guix shell`で`rake test`によるテスト実行ができます。
|
|
63
61
|
|
|
@@ -68,6 +66,12 @@ POTファイルの生成には`rdoc --format pot`とします。
|
|
|
68
66
|
このPOTファイルから各言語のPOファイルを初期化できます。
|
|
69
67
|
例えば`msginit -i doc/rdoc.pot -o po/en.rdoc.po --locale en_US.UTF-8`です。
|
|
70
68
|
|
|
69
|
+
## 謝辞
|
|
70
|
+
|
|
71
|
+
このプロジェクトは[GitHubのiyuuya/jkf](https://github.com/iyuuya/jkf)を元にしています。
|
|
72
|
+
そこから[GitHubのgemmaro/jkf](https://github.com/gemmaro/jkf)にフォークされました。
|
|
73
|
+
現在の開発はこのGitHubリポジトリに移っています(一時期[SourceForge](https://sourceforge.net/projects/ruby-jkf/)を試していましたがTrusted PublishingのためにGitHubに戻します)。
|
|
74
|
+
|
|
71
75
|
## 利用許諾
|
|
72
76
|
|
|
73
77
|
ライセンスは[MIT License][mit]です。
|
data/jkf.gemspec
CHANGED
|
@@ -5,12 +5,12 @@ require 'jkf/version'
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = 'jkf'
|
|
7
7
|
spec.version = Jkf::VERSION
|
|
8
|
-
spec.authors = [
|
|
8
|
+
spec.authors = %w[iyuuya gemmaro]
|
|
9
9
|
spec.email = ['i.yuuya@gmail.com', 'gemmaro.dev@gmail.com']
|
|
10
10
|
|
|
11
11
|
spec.summary = 'Shogi formats parser and converter'
|
|
12
|
-
spec.description = 'The jkf gem provides parsers and converters (generaters) for several shogi formats.'
|
|
13
|
-
spec.homepage = 'https://github.com/
|
|
12
|
+
spec.description = 'The jkf gem provides parsers and converters (generaters) for several shogi formats, including json-kifu-format, KIF, KI2, and CSA.'
|
|
13
|
+
spec.homepage = 'https://github.com/gemmaro/jkf'
|
|
14
14
|
spec.license = 'MIT'
|
|
15
15
|
|
|
16
16
|
spec.required_ruby_version = '>= 3.0'
|
|
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
'rubygems_mfa_required' => 'true',
|
|
23
23
|
'documentation_uri' => 'https://www.rubydoc.info/gems/jkf'
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency "rake"
|
|
25
27
|
end
|
data/lib/jkf/converter/base.rb
CHANGED
data/lib/jkf/converter/csa.rb
CHANGED
|
@@ -8,38 +8,34 @@ module Jkf
|
|
|
8
8
|
|
|
9
9
|
def convert_root(jkf)
|
|
10
10
|
result = version
|
|
11
|
-
result
|
|
12
|
-
result
|
|
13
|
-
result
|
|
11
|
+
result << convert_information(jkf['header']) if jkf['header']
|
|
12
|
+
result << convert_initial(jkf['initial']) if jkf['initial']
|
|
13
|
+
result << convert_moves(jkf['moves']) if jkf['moves']
|
|
14
14
|
result
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def convert_information(header)
|
|
18
18
|
result = ''
|
|
19
|
-
if header['先手'] || header['下手']
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if header['後手'] || header['上手']
|
|
23
|
-
result += 'N-' + (header.delete('後手') || header.delete('上手') || '') + "\n"
|
|
24
|
-
end
|
|
25
|
-
header.each { |(k, v)| result += "$#{csa_header_key(k)}:#{v}\n" }
|
|
19
|
+
result << 'N+' + (header.delete('先手') || header.delete('下手') || '') + "\n" if header['先手'] || header['下手']
|
|
20
|
+
result << 'N-' + (header.delete('後手') || header.delete('上手') || '') + "\n" if header['後手'] || header['上手']
|
|
21
|
+
header.each { |(k, v)| result << "$#{csa_header_key(k)}:#{v}\n" }
|
|
26
22
|
result
|
|
27
23
|
end
|
|
28
24
|
|
|
29
25
|
def convert_initial(initial)
|
|
30
26
|
result = ''
|
|
31
27
|
data = initial['data'] || {}
|
|
32
|
-
result
|
|
28
|
+
result << if initial['preset'] == 'OTHER'
|
|
33
29
|
convert_board(data['board'])
|
|
34
30
|
else
|
|
35
31
|
convert_preset(initial['preset'])
|
|
36
32
|
end
|
|
37
33
|
# 持駒
|
|
38
34
|
if data['hands']
|
|
39
|
-
result
|
|
40
|
-
result
|
|
35
|
+
result << convert_hands(data['hands'], 0)
|
|
36
|
+
result << convert_hands(data['hands'], 1)
|
|
41
37
|
end
|
|
42
|
-
result
|
|
38
|
+
result << csa_color(data['color']) + "\n" if data['color']
|
|
43
39
|
result
|
|
44
40
|
end
|
|
45
41
|
|
|
@@ -48,9 +44,9 @@ module Jkf
|
|
|
48
44
|
sum = 0
|
|
49
45
|
hands[color].each_value { |n| sum += n }
|
|
50
46
|
if sum > 0
|
|
51
|
-
result
|
|
52
|
-
hands[color].to_a.reverse_each { |(k, v)| v.times { result
|
|
53
|
-
result
|
|
47
|
+
result << "P#{csa_color(color)}"
|
|
48
|
+
hands[color].to_a.reverse_each { |(k, v)| v.times { result << "00#{k}" } }
|
|
49
|
+
result << "\n"
|
|
54
50
|
end
|
|
55
51
|
result
|
|
56
52
|
end
|
|
@@ -60,14 +56,15 @@ module Jkf
|
|
|
60
56
|
before_pos = nil
|
|
61
57
|
moves.each do |move|
|
|
62
58
|
next if move == {}
|
|
63
|
-
|
|
64
|
-
result
|
|
59
|
+
|
|
60
|
+
result << convert_move(move['move'], before_pos) if move['move']
|
|
61
|
+
result << convert_special(move['special'], move['color']) if move['special']
|
|
65
62
|
if move['time']
|
|
66
|
-
result
|
|
63
|
+
result << ',' + convert_time(move['time'])
|
|
67
64
|
elsif move['move'] || move['special']
|
|
68
|
-
result
|
|
65
|
+
result << "\n"
|
|
69
66
|
end
|
|
70
|
-
result
|
|
67
|
+
result << convert_comments(move['comments']) if move['comments']
|
|
71
68
|
before_pos = move['move']['to'] if move['move'] && move['move']['to']
|
|
72
69
|
end
|
|
73
70
|
result
|
|
@@ -75,8 +72,8 @@ module Jkf
|
|
|
75
72
|
|
|
76
73
|
def convert_move(move, before_pos)
|
|
77
74
|
result = csa_color(move['color'])
|
|
78
|
-
result
|
|
79
|
-
result
|
|
75
|
+
result << (move['from'] ? pos2str(move['from']) : '00')
|
|
76
|
+
result << if move['to']
|
|
80
77
|
pos2str(move['to']) + move['piece']
|
|
81
78
|
else
|
|
82
79
|
pos2str(before_pos) + move['piece']
|
|
@@ -86,8 +83,8 @@ module Jkf
|
|
|
86
83
|
|
|
87
84
|
def convert_special(special, color = nil)
|
|
88
85
|
result = '%'
|
|
89
|
-
result
|
|
90
|
-
result
|
|
86
|
+
result << csa_color(color) if color
|
|
87
|
+
result << special
|
|
91
88
|
end
|
|
92
89
|
|
|
93
90
|
def convert_time(time)
|
|
@@ -102,22 +99,22 @@ module Jkf
|
|
|
102
99
|
def convert_board(board)
|
|
103
100
|
result = ''
|
|
104
101
|
9.times do |y|
|
|
105
|
-
result
|
|
102
|
+
result << "P#{y + 1}"
|
|
106
103
|
9.times do |x|
|
|
107
104
|
piece = board[8 - x][y]
|
|
108
|
-
result
|
|
105
|
+
result << if piece == {}
|
|
109
106
|
' * '
|
|
110
107
|
else
|
|
111
108
|
csa_color(piece['color']) + piece['kind']
|
|
112
109
|
end
|
|
113
110
|
end
|
|
114
|
-
result
|
|
111
|
+
result << "\n"
|
|
115
112
|
end
|
|
116
113
|
result
|
|
117
114
|
end
|
|
118
115
|
|
|
119
116
|
def convert_preset(preset)
|
|
120
|
-
'PI'
|
|
117
|
+
'PI' << PRESET_NAME_TO_CSA_MAPPING[preset]
|
|
121
118
|
end
|
|
122
119
|
|
|
123
120
|
PRESET_NAME_TO_CSA_MAPPING = {
|
|
@@ -144,7 +141,7 @@ module Jkf
|
|
|
144
141
|
end
|
|
145
142
|
|
|
146
143
|
def pos2str(pos)
|
|
147
|
-
'%d%d'
|
|
144
|
+
format('%d%d', pos['x'], pos['y'])
|
|
148
145
|
end
|
|
149
146
|
|
|
150
147
|
def version
|
data/lib/jkf/converter/ki2.rb
CHANGED
|
@@ -11,13 +11,13 @@ module Jkf
|
|
|
11
11
|
setup_players!(jkf)
|
|
12
12
|
|
|
13
13
|
result = ''
|
|
14
|
-
result
|
|
15
|
-
result
|
|
16
|
-
result
|
|
17
|
-
result
|
|
14
|
+
result << convert_header(jkf['header']) if jkf['header']
|
|
15
|
+
result << convert_initial(jkf['initial']) if jkf['initial']
|
|
16
|
+
result << @header2.join + "\n"
|
|
17
|
+
result << convert_moves(jkf['moves']) if jkf['moves']
|
|
18
18
|
unless @forks.empty?
|
|
19
|
-
result
|
|
20
|
-
result
|
|
19
|
+
result << "\n"
|
|
20
|
+
result << @forks.join("\n")
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
result
|
|
@@ -53,22 +53,22 @@ module Jkf
|
|
|
53
53
|
moves.each_with_index do |move, i|
|
|
54
54
|
if move['special']
|
|
55
55
|
# first_board+speical分を引く(-2)
|
|
56
|
-
result
|
|
56
|
+
result << convert_special_and_split(move, i + idx - 2)
|
|
57
57
|
else
|
|
58
|
-
result
|
|
58
|
+
result << before_split
|
|
59
59
|
if move['move']
|
|
60
60
|
j += 1
|
|
61
61
|
result_move, before_split = convert_move_and_split(move, j)
|
|
62
|
-
result
|
|
62
|
+
result << result_move
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
if move['comments']
|
|
66
66
|
unless result.end_with?("\n") || result.empty?
|
|
67
|
-
result
|
|
67
|
+
result << "\n"
|
|
68
68
|
before_split = ''
|
|
69
69
|
j = 0
|
|
70
70
|
end
|
|
71
|
-
result
|
|
71
|
+
result << convert_comments(move['comments'])
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
@forks.unshift convert_forks(move['forks'], i + idx) if move['forks']
|
|
@@ -93,8 +93,8 @@ module Jkf
|
|
|
93
93
|
|
|
94
94
|
def convert_move(move)
|
|
95
95
|
result = move['color'] == 0 ? '▲' : '△'
|
|
96
|
-
result
|
|
97
|
-
result
|
|
96
|
+
result << convert_piece_with_pos(move)
|
|
97
|
+
result << csa2relative(move['relative']) if move['relative']
|
|
98
98
|
result
|
|
99
99
|
end
|
|
100
100
|
|
data/lib/jkf/converter/kif.rb
CHANGED
|
@@ -11,14 +11,14 @@ module Jkf
|
|
|
11
11
|
setup_players!(jkf)
|
|
12
12
|
|
|
13
13
|
result = ''
|
|
14
|
-
result
|
|
15
|
-
result
|
|
16
|
-
result
|
|
17
|
-
result
|
|
18
|
-
result
|
|
14
|
+
result << convert_header(jkf['header'], jkf) if jkf['header']
|
|
15
|
+
result << convert_initial(jkf['initial']) if jkf['initial']
|
|
16
|
+
result << @header2.join
|
|
17
|
+
result << "手数----指手---------消費時間--\n"
|
|
18
|
+
result << convert_moves(jkf['moves'])
|
|
19
19
|
unless @forks.empty?
|
|
20
|
-
result
|
|
21
|
-
result
|
|
20
|
+
result << "\n"
|
|
21
|
+
result << @forks.join("\n")
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
result
|
|
@@ -46,10 +46,10 @@ module Jkf
|
|
|
46
46
|
result = ''
|
|
47
47
|
moves.each_with_index do |move, i|
|
|
48
48
|
if move['special']
|
|
49
|
-
result
|
|
49
|
+
result << convert_special_line(move, i + idx)
|
|
50
50
|
else
|
|
51
|
-
result
|
|
52
|
-
result
|
|
51
|
+
result << convert_move_line(move, i + idx) if move['move']
|
|
52
|
+
result << convert_comments(move['comments']) if move['comments']
|
|
53
53
|
@forks.unshift convert_forks(move['forks'], i + idx) if move['forks']
|
|
54
54
|
end
|
|
55
55
|
end
|
|
@@ -57,26 +57,26 @@ module Jkf
|
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def convert_move_line(move, index)
|
|
60
|
-
result = '%4d '
|
|
61
|
-
result
|
|
62
|
-
result
|
|
63
|
-
result
|
|
64
|
-
result
|
|
60
|
+
result = format('%4d ', index)
|
|
61
|
+
result << convert_move(move['move'])
|
|
62
|
+
result << convert_time(move['time']) if move['time']
|
|
63
|
+
result << '+' if move['forks']
|
|
64
|
+
result << "\n"
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
def convert_special_line(move, index)
|
|
68
|
-
result = '%4d '
|
|
69
|
-
result
|
|
70
|
-
result
|
|
71
|
-
result
|
|
72
|
-
result
|
|
68
|
+
result = format('%4d ', index)
|
|
69
|
+
result << ljust(special2kan(move['special']), 13)
|
|
70
|
+
result << convert_time(move['time']) if move['time']
|
|
71
|
+
result << '+' if move['forks']
|
|
72
|
+
result << "\n"
|
|
73
73
|
# first_board+speical分を引く(-2)
|
|
74
|
-
result
|
|
74
|
+
result << convert_special(move['special'], index - 2)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def convert_move(move)
|
|
78
78
|
result = convert_piece_with_pos(move)
|
|
79
|
-
result
|
|
79
|
+
result << if move['from']
|
|
80
80
|
"(#{pos2str(move['from'])})"
|
|
81
81
|
else
|
|
82
82
|
'打'
|
|
@@ -85,13 +85,8 @@ module Jkf
|
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
def convert_time(time)
|
|
88
|
-
'(%2d:%02d/%02d:%02d:%02d)'
|
|
89
|
-
|
|
90
|
-
time['now']['s'],
|
|
91
|
-
time['total']['h'],
|
|
92
|
-
time['total']['m'],
|
|
93
|
-
time['total']['s']
|
|
94
|
-
]
|
|
88
|
+
format('(%2d:%02d/%02d:%02d:%02d)', time['now']['m'], time['now']['s'], time['total']['h'], time['total']['m'],
|
|
89
|
+
time['total']['s'])
|
|
95
90
|
end
|
|
96
91
|
|
|
97
92
|
def special2kan(special)
|
|
@@ -119,7 +114,7 @@ module Jkf
|
|
|
119
114
|
end
|
|
120
115
|
|
|
121
116
|
def pos2str(pos)
|
|
122
|
-
'%d%d'
|
|
117
|
+
format('%d%d', pos['x'], pos['y'])
|
|
123
118
|
end
|
|
124
119
|
end
|
|
125
120
|
end
|
|
@@ -10,16 +10,16 @@ module Jkf
|
|
|
10
10
|
|
|
11
11
|
data = initial['data']
|
|
12
12
|
if data
|
|
13
|
-
result
|
|
13
|
+
result << convert_teban(data, 1)
|
|
14
14
|
if (hands = data['hands'])
|
|
15
|
-
result
|
|
16
|
-
footer
|
|
15
|
+
result << convert_hands(hands, 1) if hands[1]
|
|
16
|
+
footer << convert_hands(hands, 0) if hands[0]
|
|
17
17
|
end
|
|
18
|
-
footer
|
|
18
|
+
footer << convert_teban(data, 0)
|
|
19
19
|
|
|
20
|
-
result
|
|
20
|
+
result << convert_board(data['board']) if data['board']
|
|
21
21
|
end
|
|
22
|
-
result
|
|
22
|
+
result << footer
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def convert_handicap(preset)
|
|
@@ -39,12 +39,12 @@ module Jkf
|
|
|
39
39
|
9.times do |y|
|
|
40
40
|
line = '|'
|
|
41
41
|
9.times do |x|
|
|
42
|
-
line
|
|
42
|
+
line << convert_board_piece(board[8 - x][y])
|
|
43
43
|
end
|
|
44
|
-
line
|
|
45
|
-
result
|
|
44
|
+
line << "|#{n2kan(y + 1)}\n"
|
|
45
|
+
result << line
|
|
46
46
|
end
|
|
47
|
-
result
|
|
47
|
+
result << "+---------------------------+\n"
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def convert_comments(comments)
|
|
@@ -56,9 +56,9 @@ module Jkf
|
|
|
56
56
|
if num > 0
|
|
57
57
|
str = csa2kind(piece)
|
|
58
58
|
if num > 1
|
|
59
|
-
str
|
|
59
|
+
str << n2kan(num / 10) if num / 10 > 0
|
|
60
60
|
num %= 10
|
|
61
|
-
str
|
|
61
|
+
str << n2kan(num)
|
|
62
62
|
end
|
|
63
63
|
str
|
|
64
64
|
end
|
|
@@ -71,8 +71,8 @@ module Jkf
|
|
|
71
71
|
if piece == {}
|
|
72
72
|
result = ' ・'
|
|
73
73
|
else
|
|
74
|
-
result
|
|
75
|
-
result
|
|
74
|
+
result << (piece['color'] == 0 ? ' ' : 'v')
|
|
75
|
+
result << csa2kind(piece['kind'])
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
result
|
|
@@ -83,13 +83,13 @@ module Jkf
|
|
|
83
83
|
|
|
84
84
|
if special == 'TORYO' || special.include?('ILLEGAL')
|
|
85
85
|
turn = @players[index % 2]
|
|
86
|
-
result
|
|
87
|
-
result
|
|
86
|
+
result << "で#{turn}手の"
|
|
87
|
+
result << { 'TORYO' => '勝ち',
|
|
88
88
|
'ILLEGAL_ACTION' => '反則勝ち',
|
|
89
89
|
'ILLEGAL_MOVE' => '反則負け' }[special]
|
|
90
90
|
else
|
|
91
91
|
turn = @players[(index + 1) % 2]
|
|
92
|
-
result
|
|
92
|
+
result << case special
|
|
93
93
|
when 'TIME_UP' then "で時間切れにより#{turn}手の勝ち"
|
|
94
94
|
when 'CHUDAN' then 'で中断'
|
|
95
95
|
when 'JISHOGI' then 'で持将棋'
|
|
@@ -99,7 +99,7 @@ module Jkf
|
|
|
99
99
|
end
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
-
result
|
|
102
|
+
result << "\n"
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def convert_piece_with_pos(move)
|
|
@@ -108,16 +108,16 @@ module Jkf
|
|
|
108
108
|
elsif move['same']
|
|
109
109
|
'同 '
|
|
110
110
|
end
|
|
111
|
-
result
|
|
112
|
-
result
|
|
111
|
+
result << csa2kind(move['piece'])
|
|
112
|
+
result << '成' if move['promote']
|
|
113
113
|
result
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
def convert_forks(forks, index)
|
|
117
117
|
result = "\n"
|
|
118
|
-
result = "変化:%4d手\n"
|
|
118
|
+
result = format("変化:%4d手\n", index) # ki2の場合\nなし
|
|
119
119
|
forks.each do |moves|
|
|
120
|
-
result
|
|
120
|
+
result << convert_moves(moves, index)
|
|
121
121
|
end
|
|
122
122
|
result
|
|
123
123
|
end
|
|
@@ -131,9 +131,9 @@ module Jkf
|
|
|
131
131
|
players_flag = :sengo
|
|
132
132
|
jkf['header']&.keys&.detect { |key| key =~ /[上下]手/ } && players_flag = :uwasimo
|
|
133
133
|
@players = if players_flag == :uwasimo
|
|
134
|
-
[
|
|
134
|
+
%w[下 上]
|
|
135
135
|
else
|
|
136
|
-
[
|
|
136
|
+
%w[先 後]
|
|
137
137
|
end
|
|
138
138
|
end
|
|
139
139
|
|