Add shogi PSN load/save support.
[kaya.git] / lib / games / shogi / piece.rb
blobd8ce6904cabf576832805ce97643f6d201297af4
1 require 'games/chess/piece'
3 module Shogi
5 class Piece < Chess::Piece
6   TYPES = { 'P' => :pawn,
7             'R' => :rook,
8             'B' => :bishop,
9             'N' => :horse,
10             'G' => :gold,
11             'S' => :silver, 
12             'L' => :lance,
13             'K' => :king }
14   SYMBOLS = TYPES.invert
15   
16   def self.type_from_symbol(sym)
17     promoted = sym[0,1] == '+'
18     sym = sym[1..-1] if promoted
19     type = TYPES[sym.upcase]
20     type = ('promoted_' + type.to_s).to_sym if promoted
21     type
22   end
23   
24   def self.symbol(type)
25     promoted = type.to_s =~ /^promoted_/
26     base_type = if promoted
27       type.to_s.gsub(/^promoted_/, '').to_sym
28     else
29       type
30     end
31     result = SYMBOLS[base_type] || '?'
32     result = '+' + result if promoted
33     result
34   end
35 end
37 end