jkf 0.3.0 → 0.3.1

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: 5c91b3b16debff343f298891452919ea2ec20527
4
- data.tar.gz: b7c82914f613103e23087dd55f824da707846ca8
3
+ metadata.gz: bc949b63200215816a909361e5bfd25e7e500a75
4
+ data.tar.gz: 4c3401109c8a2605ec059125150da420bf765bb9
5
5
  SHA512:
6
- metadata.gz: c38021483c7d0457332083545ae03081f45de7bd8c43378d6c66f656cc0436f308422a253822a3545152c597a56621ffeccdb5e45e722faa0f1c6fc0ec8208ae
7
- data.tar.gz: 41dae1d0deaed3ed33d21955429ab23f7f70f0e316b77dd0637b64b4412a36058a150be2cccd547cdb31774caeabe853c8cd14ce8e7bc00a710c033dcae24ccc
6
+ metadata.gz: 64198f8a7885426c309a9700ec4e576363bdf339f0e523a4b0ea0375552fc4d51ca5f457945cb7271fc585dc494ccf3d9f75132620dbecdc306b05c01d887f97
7
+ data.tar.gz: 298dd0d297f5897fd1cf4065d00a6d49e687fc577c8fc7368a71981689ba87aaa6d9cbfe099f3bd87b4201d85f7ef59352fc5a8ced0da415af1d489b2b4725fb
@@ -168,7 +168,7 @@ module Jkf::Converter
168
168
  end
169
169
 
170
170
  def convert_motigoma(pieces)
171
- pieces.map do |piece, num|
171
+ pieces.to_a.reverse.map do |(piece, num)|
172
172
  if num > 0
173
173
  str = csa2kind(piece)
174
174
  if num > 1
@@ -184,7 +184,7 @@ module Jkf::Converter
184
184
  end
185
185
 
186
186
  def convert_motigoma(pieces)
187
- pieces.map do |piece, num|
187
+ pieces.to_a.reverse.map do |piece, num|
188
188
  if num > 0
189
189
  str = csa2kind(piece)
190
190
  if num > 1
@@ -57,7 +57,7 @@ module Jkf::Parser
57
57
  end
58
58
  if ret["initial"] && ret["initial"]["data"]
59
59
  if ret["header"]["手番"]
60
- ret["initial"]["data"]["color"] = ("下先".index(ret["header"]["手番"]) >= 0 ? 0 : 1)
60
+ ret["initial"]["data"]["color"] = ("下先".include?(ret["header"]["手番"]) ? 0 : 1)
61
61
  ret["header"].delete("手番")
62
62
  else
63
63
  ret["initial"]["data"]["color"] = 0
@@ -81,6 +81,7 @@ module Jkf::Parser
81
81
  fork_stack << _fork
82
82
  fork_stack << now_fork
83
83
  end
84
+ reverse_color(ret['moves']) if ret["initial"] && ret["initial"]["data"] && ret["initial"]["data"]["color"] == 1
84
85
  ret
85
86
  }.call(s2, s3, s4, s6, s7)
86
87
  s0 = s1
@@ -634,8 +635,8 @@ module Jkf::Parser
634
635
  s6 = parse_from
635
636
  if s6 != :failed
636
637
  @reported_pos = s4
637
- s5 = -> (fugou, from) {
638
- ret = { "piece" => fugou["piece"] }
638
+ s5 = -> (teban, fugou, from) {
639
+ ret = { "color" => teban2color(teban.join), "piece" => fugou["piece"] }
639
640
  if fugou["to"]
640
641
  ret["to"] = fugou["to"]
641
642
  else
@@ -644,7 +645,7 @@ module Jkf::Parser
644
645
  ret["promote"] = true if fugou["promote"]
645
646
  ret["from"] = from if from
646
647
  ret
647
- }.call(s5, s6)
648
+ }.call(s2, s5, s6)
648
649
  s4 = s5
649
650
  else
650
651
  @current_pos = s4
@@ -1519,6 +1520,11 @@ module Jkf::Parser
1519
1520
  }[preset.gsub(/\s/, "")]
1520
1521
  end
1521
1522
 
1523
+ def teban2color(teban)
1524
+ teban = teban.to_i unless teban.is_a? Fixnum
1525
+ (teban+1) % 2
1526
+ end
1527
+
1522
1528
  def make_hand(str)
1523
1529
  # Kifu for iPhoneは半角スペース区切り
1524
1530
  kinds = str.split(/[  ]/)
@@ -1532,5 +1538,12 @@ module Jkf::Parser
1532
1538
 
1533
1539
  ret
1534
1540
  end
1541
+
1542
+ def reverse_color(moves)
1543
+ moves.each do |move|
1544
+ move['move']['color'] = (move['move']['color'] + 1) % 2 if move['move'] && move['move']['color']
1545
+ move['forks'].each { |_fork| reverse_color(_fork) } if move['forks']
1546
+ end
1547
+ end
1535
1548
  end
1536
1549
  end
data/lib/jkf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jkf
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
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.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - iyuuya