jkf 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc949b63200215816a909361e5bfd25e7e500a75
4
- data.tar.gz: 4c3401109c8a2605ec059125150da420bf765bb9
3
+ metadata.gz: 80b961d103b0c7155b4ac36d77e9d3ddb40a03a3
4
+ data.tar.gz: b22def70291acf60b94fa289614fd8b254c6ac8f
5
5
  SHA512:
6
- metadata.gz: 64198f8a7885426c309a9700ec4e576363bdf339f0e523a4b0ea0375552fc4d51ca5f457945cb7271fc585dc494ccf3d9f75132620dbecdc306b05c01d887f97
7
- data.tar.gz: 298dd0d297f5897fd1cf4065d00a6d49e687fc577c8fc7368a71981689ba87aaa6d9cbfe099f3bd87b4201d85f7ef59352fc5a8ced0da415af1d489b2b4725fb
6
+ metadata.gz: 2f7e92e39cf7caa4de99366b4645de4a42a57d664eb8b10e832d1fa651a03d07d053c3f3f5eb4685a4cde3bc38f65b7c5166b8c0f65acb0d5aee33c5240d0264
7
+ data.tar.gz: dca0b0cbe829920b2ef816e138592965f4b62e7ca00115de5509558853987b56150f3a11b8af6a3fb7443cfeb8102e87a0710a1bcd4cd8de5ad613ae5e826c53
@@ -8,9 +8,19 @@ module Jkf::Converter
8
8
  end
9
9
  @forks = []
10
10
 
11
+ players_flag = :sengo
12
+ hash['header'] && hash['header'].keys.find { |key| key =~ /[上下]手/ } && players_flag = :uwasimo
13
+ @players = if players_flag == :uwasimo
14
+ ['下', '上']
15
+ else
16
+ ['先', '後']
17
+ end
18
+ @header2 = []
19
+
11
20
  result = ''
12
21
  result += convert_header(hash['header']) if hash['header']
13
22
  result += convert_initial(hash['initial']) if hash['initial']
23
+ result += @header2.join
14
24
  result += convert_moves(hash['moves']) if hash['moves']
15
25
  if @forks.size > 0
16
26
  result += "\n"
@@ -21,33 +31,45 @@ module Jkf::Converter
21
31
  end
22
32
 
23
33
  def convert_header(header)
24
- header.map { |(key, value)| "#{key}:#{value}\n" }.join
34
+ header.map { |(key, value)|
35
+ result = "#{key}:#{value}\n"
36
+ if key =~ /\A[先後上下]手\Z/
37
+ if key =~ /[先下]/
38
+ @header2.unshift result
39
+ else
40
+ @header2 << result
41
+ end
42
+ nil
43
+ else
44
+ result
45
+ end
46
+ }.compact.join
25
47
  end
26
48
 
49
+
27
50
  def convert_initial(initial)
28
51
  result = ''
29
52
  result += "手合割:#{preset2str(initial["preset"])}\n" if initial["preset"] != "OTHER"
53
+ footer = ''
30
54
 
31
55
  data = initial["data"]
32
56
 
33
57
  if data
34
- if data['color'] == 0
35
- result += "先手番\n"
36
- elsif data['color'] == 1
37
- result += "後手番\n"
38
- end
58
+ result += "#{@players[1]}手番\n" if data['color'] == 1
39
59
 
40
60
  if data['hands']
41
- if data['hands'][0]
42
- result += '先手の持駒:'
43
- result += convert_motigoma(data['hands'][0])
44
- end
45
61
  if data['hands'][1]
46
- result += '後手の持駒:'
62
+ result += "#{@players[1]}手の持駒:"
47
63
  result += convert_motigoma(data['hands'][1])
48
64
  end
65
+ if data['hands'][0]
66
+ footer += "#{@players[0]}手の持駒:"
67
+ footer += convert_motigoma(data['hands'][0])
68
+ end
49
69
  end
50
70
 
71
+ footer += "#{@players[0]}手番\n" if data['color'] == 0
72
+
51
73
  if data['board']
52
74
  result += " 9 8 7 6 5 4 3 2 1\n"
53
75
  result += "+---------------------------+\n"
@@ -63,6 +85,8 @@ module Jkf::Converter
63
85
  end
64
86
  end
65
87
 
88
+ result += footer
89
+
66
90
  result
67
91
  end
68
92
 
@@ -119,7 +143,7 @@ module Jkf::Converter
119
143
  result = "まで#{index+1}手"
120
144
 
121
145
  if special == 'TORYO' || special =~ /ILLEGAL/
122
- turn = index % 2 == 0 ? '後' : '先'
146
+ turn = @players[index % 2]
123
147
  result += "で#{turn}手の"
124
148
  result += case special
125
149
  when "TORYO" then "勝ち"
@@ -127,7 +151,7 @@ module Jkf::Converter
127
151
  when "ILLEGAL_MOVE" then "反則負け"
128
152
  end
129
153
  else
130
- turn = index % 2 == 0 ? '先' : '後'
154
+ turn = @players[(index+1) % 2]
131
155
  result += case special
132
156
  when "TIME_UP" then "で時間切れにより#{turn}手の勝ち"
133
157
  when "CHUDAN" then "で中断"
@@ -8,9 +8,19 @@ module Jkf::Converter
8
8
  end
9
9
  @forks = []
10
10
 
11
+ players_flag = :sengo
12
+ hash['header'] && hash['header'].keys.find { |key| key =~ /[上下]手/ } && players_flag = :uwasimo
13
+ @players = if players_flag == :uwasimo
14
+ ['下', '上']
15
+ else
16
+ ['先', '後']
17
+ end
18
+ @header2 = []
19
+
11
20
  result = ''
12
21
  result += convert_header(hash['header']) if hash['header']
13
22
  result += convert_initial(hash['initial']) if hash['initial']
23
+ result += @header2.join
14
24
  result += "手数----指手---------消費時間--\n"
15
25
  result += convert_moves(hash['moves'])
16
26
  if @forks.size > 0
@@ -24,33 +34,44 @@ module Jkf::Converter
24
34
  protected
25
35
 
26
36
  def convert_header(header)
27
- header.map { |(key, value)| "#{key}:#{value}\n" }.join
37
+ header.map { |(key, value)|
38
+ result = "#{key}:#{value}\n"
39
+ if key =~ /\A[先後上下]手\Z/
40
+ if key =~ /[先下]/
41
+ @header2.unshift result
42
+ else
43
+ @header2 << result
44
+ end
45
+ nil
46
+ else
47
+ result
48
+ end
49
+ }.compact.join
28
50
  end
29
51
 
30
52
  def convert_initial(initial)
31
53
  result = ''
32
54
  result += "手合割:#{preset2str(initial["preset"])}\n" if initial["preset"] != "OTHER"
55
+ footer = ''
33
56
 
34
57
  data = initial["data"]
35
58
 
36
59
  if data
37
- if data['color'] == 0
38
- result += "先手番\n"
39
- elsif data['color'] == 1
40
- result += "後手番\n"
41
- end
60
+ result += "#{@players[1]}手番\n" if data['color'] == 1
42
61
 
43
62
  if data['hands']
44
- if data['hands'][0]
45
- result += '先手の持駒:'
46
- result += convert_motigoma(data['hands'][0])
47
- end
48
63
  if data['hands'][1]
49
- result += '後手の持駒:'
64
+ result += "#{@players[1]}手の持駒:"
50
65
  result += convert_motigoma(data['hands'][1])
51
66
  end
67
+ if data['hands'][0]
68
+ footer += "#{@players[0]}手の持駒:"
69
+ footer += convert_motigoma(data['hands'][0])
70
+ end
52
71
  end
53
72
 
73
+ footer += "#{@players[0]}手番\n" if data['color'] == 0
74
+
54
75
  if data['board']
55
76
  result += " 9 8 7 6 5 4 3 2 1\n"
56
77
  result += "+---------------------------+\n"
@@ -66,6 +87,8 @@ module Jkf::Converter
66
87
  end
67
88
  end
68
89
 
90
+ result += footer
91
+
69
92
  result
70
93
  end
71
94
 
@@ -134,7 +157,7 @@ module Jkf::Converter
134
157
  result = "まで#{index+1}手"
135
158
 
136
159
  if special == 'TORYO' || special =~ /ILLEGAL/
137
- turn = index % 2 == 0 ? '後' : '先'
160
+ turn = @players[index % 2]
138
161
  result += "で#{turn}手の"
139
162
  result += case special
140
163
  when "TORYO" then "勝ち"
@@ -142,7 +165,7 @@ module Jkf::Converter
142
165
  when "ILLEGAL_MOVE" then "反則負け"
143
166
  end
144
167
  else
145
- turn = index % 2 == 0 ? '先' : '後'
168
+ turn = @players[(index+1) % 2]
146
169
  result += case special
147
170
  when "TIME_UP" then "で時間切れにより#{turn}手の勝ち"
148
171
  when "CHUDAN" then "で中断"
data/lib/jkf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jkf
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jkf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - iyuuya