jkf 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.envrc +1 -0
- data/.rubocop.yml +67 -0
- data/.rubocop_todo.yml +1 -454
- data/.yardopts +4 -0
- data/CHANGELOG.md +27 -0
- data/Gemfile +12 -11
- data/Guardfile +3 -3
- data/README.en.md +27 -23
- data/README.md +32 -21
- data/Rakefile +4 -4
- data/bench.rb +12 -0
- data/bin/console +4 -4
- data/jkf.gemspec +16 -15
- data/lib/jkf/converter/base.rb +12 -10
- data/lib/jkf/converter/csa.rb +141 -150
- data/lib/jkf/converter/ki2.rb +94 -92
- data/lib/jkf/converter/kif.rb +105 -99
- data/lib/jkf/converter/kifuable.rb +160 -160
- data/lib/jkf/converter.rb +6 -8
- data/lib/jkf/parser/base.rb +81 -95
- data/lib/jkf/parser/csa.rb +651 -654
- data/lib/jkf/parser/ki2.rb +331 -333
- data/lib/jkf/parser/kif.rb +467 -468
- data/lib/jkf/parser/kifuable.rb +511 -517
- data/lib/jkf/parser.rb +5 -7
- data/lib/jkf/version.rb +1 -2
- data/lib/jkf.rb +6 -6
- data/manifest.scm +3 -30
- data/po/all.pot +64 -48
- data/po/en.po +83 -82
- data/po/en.rdoc.po +580 -0
- metadata +18 -10
data/README.en.md
CHANGED
@@ -1,38 +1,40 @@
|
|
1
|
-
#
|
1
|
+
# jkf gem
|
2
|
+
|
2
3
|
[![Gem
|
3
4
|
Version](https://badge.fury.io/rb/jkf.svg)](https://badge.fury.io/rb/jkf)
|
4
5
|
[![Build
|
5
6
|
Status](https://travis-ci.org/iyuuya/jkf.svg?branch=master)](https://travis-ci.org/iyuuya/jkf)
|
6
7
|
[![CI](https://github.com/iyuuya/jkf/actions/workflows/ci.yml/badge.svg)](https://github.com/iyuuya/jkf/actions/workflows/ci.yml)
|
7
|
-
[![Inline
|
8
|
-
docs](http://inch-ci.org/github/iyuuya/jkf.svg?branch=develop)](http://inch-ci.org/github/iyuuya/jkf)
|
9
8
|
|
10
|
-
jkf is a Ruby port of
|
11
|
-
[
|
12
|
-
|
13
|
-
|
9
|
+
The jkf gem is a Ruby port of [json-kifu-format (JKF)][jkf].
|
10
|
+
It supports both of the conversion from KIF (see [棋譜ファイル KIF 形式][kakinoki]),
|
11
|
+
KI2, or CSA (see [CSA標準棋譜ファイル形式][csa]) to JKF, and the one from JKF to KIF,
|
12
|
+
KI2, or CSA.
|
13
|
+
|
14
|
+
[csa]: http://www2.computer-shogi.org/protocol/record_v22.html
|
15
|
+
[jkf]:
|
16
|
+
https://github.com/na2hiro/Kifu-for-JS/tree/master/packages/json-kifu-format
|
17
|
+
[kakinoki]: http://kakinoki.o.oo7.jp/kif_format.html
|
14
18
|
|
15
19
|
## Installation
|
16
20
|
|
17
|
-
If you install this gem to your application (with Bundler), add
|
18
|
-
Gemfile
|
21
|
+
If you install this gem to your application (with [Bundler][bundler]), add
|
22
|
+
this to `Gemfile`.
|
23
|
+
|
24
|
+
[bundler]: https://bundler.io/
|
19
25
|
|
20
26
|
```ruby
|
21
27
|
gem 'jkf'
|
22
28
|
```
|
23
29
|
|
24
|
-
Then run bundle to install this gem.
|
30
|
+
Then run `bundle` to install this gem.
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
Or directly install with gem install command.
|
29
|
-
|
30
|
-
$ gem install jkf
|
32
|
+
Or directly install with `gem install` command.
|
31
33
|
|
32
34
|
## Usage
|
33
35
|
|
34
|
-
This gem has the Parser and the Converter for
|
35
|
-
CSA.
|
36
|
+
This gem has the parser {Jkf::Parser} and the converter {Jkf::Converter} for
|
37
|
+
each formats: KIF, KI2, and CSA.
|
36
38
|
|
37
39
|
```ruby
|
38
40
|
kif_parser = Jkf::Parser::Kif.new
|
@@ -46,8 +48,8 @@ ki2_converter = Jkf::Converter::Ki2.new
|
|
46
48
|
csa_converter = Jkf::Converter::Csa.new
|
47
49
|
```
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
+
{Jkf::Parser::Base#parse} to convert into JKF.
|
52
|
+
{Jkf::Converter::Base#convert} to convert into each formats from JKF.
|
51
53
|
|
52
54
|
```ruby
|
53
55
|
jkf = kif_parser.parse(kif_str) #=> Hash
|
@@ -63,13 +65,15 @@ csa = csa_converter.convert(jkf) #=> String
|
|
63
65
|
|
64
66
|
## Contributing
|
65
67
|
|
66
|
-
Feel free to report bugs or send pull requests at
|
67
|
-
[
|
68
|
+
Feel free to report bugs or send pull requests at [the GitHub
|
69
|
+
repository][repo].
|
70
|
+
|
71
|
+
[repo]: https://github.com/iyuuya/jkf
|
68
72
|
|
69
73
|
If you work on Guix, run tests by `guix shell`.
|
70
74
|
|
71
75
|
## License
|
72
76
|
|
73
|
-
This gem is
|
74
|
-
License](http://opensource.org/licenses/MIT).
|
77
|
+
This gem is provided under the [MIT License][mit].
|
75
78
|
|
79
|
+
[mit]: http://opensource.org/licenses/MIT
|
data/README.md
CHANGED
@@ -1,28 +1,31 @@
|
|
1
|
-
#
|
2
|
-
[![Gem Version](https://badge.fury.io/rb/jkf.svg)](https://badge.fury.io/rb/jkf) [![Build Status](https://travis-ci.org/iyuuya/jkf.svg?branch=master)](https://travis-ci.org/iyuuya/jkf) [![CI](https://github.com/iyuuya/jkf/actions/workflows/ci.yml/badge.svg)](https://github.com/iyuuya/jkf/actions/workflows/ci.yml) [![Inline docs](http://inch-ci.org/github/iyuuya/jkf.svg?branch=develop)](http://inch-ci.org/github/iyuuya/jkf)
|
1
|
+
# jkf gem
|
3
2
|
|
4
|
-
jkf
|
5
|
-
KIF, KI2, CSAをパースしJKFへ変換、JKFからKIF, KI2, CSAへの変換に対応しています。
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/jkf.svg)](https://badge.fury.io/rb/jkf) [![Build Status](https://travis-ci.org/iyuuya/jkf.svg?branch=master)](https://travis-ci.org/iyuuya/jkf) [![CI](https://github.com/iyuuya/jkf/actions/workflows/ci.yml/badge.svg)](https://github.com/iyuuya/jkf/actions/workflows/ci.yml)
|
6
4
|
|
7
|
-
|
5
|
+
jkf gemは[JSON棋譜フォーマット (JKF)][jkf]をRubyに移植したものです。
|
6
|
+
柿木形式([棋譜ファイル KIF 形式][kakinoki]、KI2)、[CSA標準棋譜ファイル形式][csa]の構文解析とJKFへの変換、JKFからKIF, KI2, CSAへの変換に対応しています。
|
8
7
|
|
9
|
-
|
8
|
+
[csa]: http://www2.computer-shogi.org/protocol/record_v22.html
|
9
|
+
[jkf]: https://github.com/na2hiro/Kifu-for-JS/tree/master/packages/json-kifu-format
|
10
|
+
[kakinoki]: http://kakinoki.o.oo7.jp/kif_format.html
|
11
|
+
|
12
|
+
## インストール
|
13
|
+
|
14
|
+
アプリケーションにインストールする場合([Bundler][bundler]を使用する場合)、`Gemfile`に以下のように記述してください。
|
15
|
+
|
16
|
+
[bundler]: https://bundler.io/
|
10
17
|
|
11
18
|
```ruby
|
12
19
|
gem 'jkf'
|
13
20
|
```
|
14
21
|
|
15
|
-
|
16
|
-
|
17
|
-
$ bundle
|
22
|
+
さらに`bundle`コマンドを実行することでインストールできます。
|
18
23
|
|
19
|
-
|
24
|
+
または、`gem install`コマンドを使って直接インストールもできます。
|
20
25
|
|
21
|
-
|
26
|
+
## 使い方
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
KIF, KI2, CSAそれぞれParserとConverterが用意してあります。
|
28
|
+
KIF, KI2, CSAそれぞれ構文解析器 {Jkf::Parser} と変換器 {Jkf::Converter} が用意してあります。
|
26
29
|
|
27
30
|
```ruby
|
28
31
|
kif_parser = Jkf::Parser::Kif.new
|
@@ -36,7 +39,7 @@ ki2_converter = Jkf::Converter::Ki2.new
|
|
36
39
|
csa_converter = Jkf::Converter::Csa.new
|
37
40
|
```
|
38
41
|
|
39
|
-
|
42
|
+
{Jkf::Parser::Base#parse} でJKFへの変換、 {Jkf::Converter::Base#convert} でJKFから各形式へ変換できます。
|
40
43
|
|
41
44
|
```ruby
|
42
45
|
jkf = kif_parser.parse(kif_str) #=> Hash
|
@@ -50,15 +53,23 @@ ki2 = ki2_converter.convert(jkf) #=> String
|
|
50
53
|
csa = csa_converter.convert(jkf) #=> String
|
51
54
|
```
|
52
55
|
|
53
|
-
##
|
56
|
+
## 貢献
|
57
|
+
|
58
|
+
バグレポートやプルリクエストは[GitHubのリポジトリ][repo]でよろしくお願いします。
|
54
59
|
|
55
|
-
|
56
|
-
https://github.com/iyuuya/jkf.
|
60
|
+
[repo]: https://github.com/iyuuya/jkf
|
57
61
|
|
58
62
|
Guixで開発されている場合は`guix shell`で`rake test`によるテスト実行ができます。
|
59
63
|
|
60
|
-
|
64
|
+
翻訳はドキュメントとAPIの2種類があります。
|
65
|
+
APIについてはRDocの国際化の機能を使います。
|
66
|
+
POTファイルの生成には`rdoc --format pot`とします。
|
67
|
+
これにより`doc/rdoc.pot`が生成されます。
|
68
|
+
このPOTファイルから各言語のPOファイルを初期化できます。
|
69
|
+
例えば`msginit -i doc/rdoc.pot -o po/en.rdoc.po --locale en_US.UTF-8`です。
|
70
|
+
|
71
|
+
## 利用許諾
|
61
72
|
|
62
|
-
ライセンスはMITです。
|
63
|
-
[MIT License](http://opensource.org/licenses/MIT).
|
73
|
+
ライセンスは[MIT License][mit]です。
|
64
74
|
|
75
|
+
[mit]: http://opensource.org/licenses/MIT
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
6
|
task default: :spec
|
7
7
|
|
8
|
-
desc
|
8
|
+
desc 'translate documents'
|
9
9
|
task :translate do
|
10
|
-
sh
|
10
|
+
sh 'po4a po4a.cfg'
|
11
11
|
end
|
data/bench.rb
ADDED
data/bin/console
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'jkf'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
if require
|
10
|
+
if require 'pry'
|
11
11
|
Pry.start
|
12
12
|
else
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
15
15
|
end
|
data/jkf.gemspec
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require 'jkf/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'jkf'
|
8
7
|
spec.version = Jkf::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['iyuuya', 'gemmaro']
|
9
|
+
spec.email = ['i.yuuya@gmail.com', 'gemmaro.dev@gmail.com']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
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/iyuuya/jkf'
|
14
|
+
spec.license = 'MIT'
|
16
15
|
|
17
|
-
spec.required_ruby_version = '>=
|
16
|
+
spec.required_ruby_version = '>= 3.0'
|
18
17
|
|
19
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
-
spec.
|
21
|
-
|
22
|
-
spec.
|
23
|
-
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.metadata = {
|
22
|
+
'rubygems_mfa_required' => 'true',
|
23
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/jkf'
|
24
|
+
}
|
24
25
|
end
|
data/lib/jkf/converter/base.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
module Jkf
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module Jkf
|
2
|
+
module Converter
|
3
|
+
# Base of Converter
|
4
|
+
class Base
|
5
|
+
# start convert
|
6
|
+
#
|
7
|
+
# @param [String, Hash] jkf
|
8
|
+
# @return [String] kif or ki2 or csa text
|
9
|
+
def convert(jkf)
|
10
|
+
jkf = jkf.is_a?(Hash) ? jkf : JSON.parse(jkf)
|
11
|
+
convert_root(jkf)
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/jkf/converter/csa.rb
CHANGED
@@ -1,174 +1,165 @@
|
|
1
|
-
module Jkf
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def convert_information(header)
|
17
|
-
result = ""
|
18
|
-
if header["先手"] || header["下手"]
|
19
|
-
result += "N+" + (header.delete("先手") || header.delete("下手") || "") + "\n"
|
20
|
-
end
|
21
|
-
if header["後手"] || header["上手"]
|
22
|
-
result += "N-" + (header.delete("後手") || header.delete("上手") || "") + "\n"
|
1
|
+
module Jkf
|
2
|
+
module Converter
|
3
|
+
# CSA v2.2 Converter
|
4
|
+
class Csa < Base
|
5
|
+
VERSION = '2.2'.freeze
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
def convert_root(jkf)
|
10
|
+
result = version
|
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
|
+
result
|
23
15
|
end
|
24
|
-
header.each { |(k, v)| result += "$#{csa_header_key(k)}:#{v}\n" }
|
25
|
-
result
|
26
|
-
end
|
27
16
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
result += convert_hands(data["hands"], 0)
|
39
|
-
result += convert_hands(data["hands"], 1)
|
17
|
+
def convert_information(header)
|
18
|
+
result = ''
|
19
|
+
if header['先手'] || header['下手']
|
20
|
+
result += 'N+' + (header.delete('先手') || header.delete('下手') || '') + "\n"
|
21
|
+
end
|
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" }
|
26
|
+
result
|
40
27
|
end
|
41
|
-
result += csa_color(data["color"]) + "\n" if data["color"]
|
42
|
-
result
|
43
|
-
end
|
44
28
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
29
|
+
def convert_initial(initial)
|
30
|
+
result = ''
|
31
|
+
data = initial['data'] || {}
|
32
|
+
result += if initial['preset'] == 'OTHER'
|
33
|
+
convert_board(data['board'])
|
34
|
+
else
|
35
|
+
convert_preset(initial['preset'])
|
36
|
+
end
|
37
|
+
# 持駒
|
38
|
+
if data['hands']
|
39
|
+
result += convert_hands(data['hands'], 0)
|
40
|
+
result += convert_hands(data['hands'], 1)
|
41
|
+
end
|
42
|
+
result += csa_color(data['color']) + "\n" if data['color']
|
43
|
+
result
|
53
44
|
end
|
54
|
-
result
|
55
|
-
end
|
56
45
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
if move["time"]
|
65
|
-
result += "," + convert_time(move["time"])
|
66
|
-
elsif move["move"] || move["special"]
|
46
|
+
def convert_hands(hands, color)
|
47
|
+
result = ''
|
48
|
+
sum = 0
|
49
|
+
hands[color].each_value { |n| sum += n }
|
50
|
+
if sum > 0
|
51
|
+
result += "P#{csa_color(color)}"
|
52
|
+
hands[color].to_a.reverse_each { |(k, v)| v.times { result += "00#{k}" } }
|
67
53
|
result += "\n"
|
68
54
|
end
|
69
|
-
result
|
70
|
-
before_pos = move["move"]["to"] if move["move"] && move["move"]["to"]
|
55
|
+
result
|
71
56
|
end
|
72
|
-
result
|
73
|
-
end
|
74
57
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
58
|
+
def convert_moves(moves)
|
59
|
+
result = ''
|
60
|
+
before_pos = nil
|
61
|
+
moves.each do |move|
|
62
|
+
next if move == {}
|
63
|
+
result += convert_move(move['move'], before_pos) if move['move']
|
64
|
+
result += convert_special(move['special'], move['color']) if move['special']
|
65
|
+
if move['time']
|
66
|
+
result += ',' + convert_time(move['time'])
|
67
|
+
elsif move['move'] || move['special']
|
68
|
+
result += "\n"
|
69
|
+
end
|
70
|
+
result += convert_comments(move['comments']) if move['comments']
|
71
|
+
before_pos = move['move']['to'] if move['move'] && move['move']['to']
|
72
|
+
end
|
73
|
+
result
|
74
|
+
end
|
85
75
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
76
|
+
def convert_move(move, before_pos)
|
77
|
+
result = csa_color(move['color'])
|
78
|
+
result += move['from'] ? pos2str(move['from']) : '00'
|
79
|
+
result += if move['to']
|
80
|
+
pos2str(move['to']) + move['piece']
|
81
|
+
else
|
82
|
+
pos2str(before_pos) + move['piece']
|
83
|
+
end
|
84
|
+
result
|
85
|
+
end
|
91
86
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
87
|
+
def convert_special(special, color = nil)
|
88
|
+
result = '%'
|
89
|
+
result += csa_color(color) if color
|
90
|
+
result + special
|
91
|
+
end
|
96
92
|
|
97
|
-
|
98
|
-
|
99
|
-
|
93
|
+
def convert_time(time)
|
94
|
+
sec = (time['now']['m'] * 60) + time['now']['s']
|
95
|
+
"T#{sec}\n"
|
96
|
+
end
|
100
97
|
|
101
|
-
|
102
|
-
|
103
|
-
9.times do |y|
|
104
|
-
result += "P#{y + 1}"
|
105
|
-
9.times do |x|
|
106
|
-
piece = board[8 - x][y]
|
107
|
-
result += if piece == {}
|
108
|
-
" * "
|
109
|
-
else
|
110
|
-
csa_color(piece["color"]) + piece["kind"]
|
111
|
-
end
|
112
|
-
end
|
113
|
-
result += "\n"
|
98
|
+
def convert_comments(comments)
|
99
|
+
comments.map { |comment| "'#{comment}" }.join("\n") + "\n"
|
114
100
|
end
|
115
|
-
result
|
116
|
-
end
|
117
101
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
"
|
131
|
-
when "HIKY" # 飛香落ち
|
132
|
-
"22HI11KY91KY"
|
133
|
-
when "2" # 二枚落ち
|
134
|
-
"82HI22KA"
|
135
|
-
when "3" # 三枚落ち
|
136
|
-
"82HI22KA91KY"
|
137
|
-
when "4" # 四枚落ち
|
138
|
-
"82HI22KA11KY91KY"
|
139
|
-
when "5" # 五枚落ち
|
140
|
-
"82HI22KA81KE11KY91KY"
|
141
|
-
when "5_L" # 左五枚落ち
|
142
|
-
"82HI22KA21KE11KY91KY"
|
143
|
-
when "6" # 六枚落ち
|
144
|
-
"82HI22KA21KE81KE11KY91KY"
|
145
|
-
when "8" # 八枚落ち
|
146
|
-
"82HI22KA31GI71GI21KE81KE11KY91KY"
|
147
|
-
when "10" # 十枚落ち
|
148
|
-
"82HI22KA41KI61KI31GI71GI21KE81KE11KY91KY"
|
102
|
+
def convert_board(board)
|
103
|
+
result = ''
|
104
|
+
9.times do |y|
|
105
|
+
result += "P#{y + 1}"
|
106
|
+
9.times do |x|
|
107
|
+
piece = board[8 - x][y]
|
108
|
+
result += if piece == {}
|
109
|
+
' * '
|
110
|
+
else
|
111
|
+
csa_color(piece['color']) + piece['kind']
|
112
|
+
end
|
113
|
+
end
|
114
|
+
result += "\n"
|
149
115
|
end
|
150
|
-
|
116
|
+
result
|
117
|
+
end
|
151
118
|
|
152
|
-
|
153
|
-
|
154
|
-
|
119
|
+
def convert_preset(preset)
|
120
|
+
'PI' + PRESET_NAME_TO_CSA_MAPPING[preset]
|
121
|
+
end
|
155
122
|
|
156
|
-
|
157
|
-
|
158
|
-
|
123
|
+
PRESET_NAME_TO_CSA_MAPPING = {
|
124
|
+
'HIRATE' => '', # 平手
|
125
|
+
'KY' => '11KY', # 香落ち
|
126
|
+
'KY_R' => '91KY', # 右香落ち
|
127
|
+
'KA' => '22KA', # 角落ち
|
128
|
+
'HI' => '82HI', # 飛車落ち
|
129
|
+
'HIKY' => '22HI11KY91KY', # 飛香落ち
|
130
|
+
'2' => '82HI22KA', # 二枚落ち
|
131
|
+
'3' => '82HI22KA91KY', # 三枚落ち
|
132
|
+
'4' => '82HI22KA11KY91KY', # 四枚落ち
|
133
|
+
'5' => '82HI22KA81KE11KY91KY', # 五枚落ち
|
134
|
+
'5_L' => '82HI22KA21KE11KY91KY', # 左五枚落ち
|
135
|
+
'6' => '82HI22KA21KE81KE11KY91KY', # 六枚落ち
|
136
|
+
'8' => '82HI22KA31GI71GI21KE81KE11KY91KY', # 八枚落ち
|
137
|
+
'10' => '82HI22KA41KI61KI31GI71GI21KE81KE11KY91KY' # 十枚落ち
|
138
|
+
}.freeze
|
139
|
+
|
140
|
+
private_constant :PRESET_NAME_TO_CSA_MAPPING
|
141
|
+
|
142
|
+
def csa_color(color)
|
143
|
+
color == 0 ? '+' : '-'
|
144
|
+
end
|
159
145
|
|
160
|
-
|
161
|
-
|
162
|
-
|
146
|
+
def pos2str(pos)
|
147
|
+
'%d%d' % [pos['x'], pos['y']]
|
148
|
+
end
|
149
|
+
|
150
|
+
def version
|
151
|
+
"V#{VERSION}\n"
|
152
|
+
end
|
163
153
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
154
|
+
def csa_header_key(key)
|
155
|
+
{
|
156
|
+
'棋戦' => 'EVENT',
|
157
|
+
'場所' => 'SITE',
|
158
|
+
'開始日時' => 'START_TIME',
|
159
|
+
'終了日時' => 'END_TIME',
|
160
|
+
'持ち時間' => 'TIME_LIMIT'
|
161
|
+
}[key] || key
|
162
|
+
end
|
172
163
|
end
|
173
164
|
end
|
174
165
|
end
|