lib/jkf/converter/csa.rb in jkf-0.4.2 vs lib/jkf/converter/csa.rb in jkf-0.4.3

- old
+ new

@@ -25,11 +25,11 @@ result end def convert_initial(initial) result = "" - data = initial["data"] + data = initial["data"] || {} result += if initial["preset"] == "OTHER" convert_board(data["board"]) else convert_preset(initial["preset"]) end @@ -54,28 +54,35 @@ result end def convert_moves(moves) result = "" + before_pos = nil moves.each do |move| next if move == {} - result += convert_move(move["move"]) if move["move"] + result += convert_move(move["move"], before_pos) if move["move"] result += convert_special(move["special"], move["color"]) if move["special"] if move["time"] result += "," + convert_time(move["time"]) elsif move["move"] || move["special"] result += "\n" end result += convert_comments(move["comments"]) if move["comments"] + before_pos = move["move"]["to"] if move["move"] && move["move"]["to"] end result end - def convert_move(move) + def convert_move(move, before_pos) result = csa_color(move["color"]) result += move["from"] ? pos2str(move["from"]) : "00" - result + pos2str(move["to"]) + move["piece"] + result += if move["to"] + pos2str(move["to"]) + move["piece"] + else + pos2str(before_pos) + move["piece"] + end + result end def convert_special(special, color = nil) result = "%" result += csa_color(color) if color @@ -109,10 +116,11 @@ end def convert_preset(preset) "PI" + case preset - when "HIRATE" + when "HIRATE" # 平手 + "" when "KY" # 香落ち "11KY" when "KY_R" # 右香落ち "91KY" when "KA" # 角落ち