-module ShogiServer
-class Board
- def set_from_str(strs)
- strs.split(/\n/).each do |str|
- if (str =~ /^P\d/)
- str.sub!(/^P(.)/, '')
- y = $1.to_i
- x = 9
- while (str.length > 2)
- str.sub!(/^(...?)/, '')
- one = $1
- if (one =~ /^([\+\-])(..)/)
- sg = $1
- name = $2
- if (sg == "+")
- sente = true
- else
- sente = false
- end
- if ((x < 1) || (9 < x) || (y < 1) || (9 < y))
- raise "bad position #{x} #{y}"
- end
- case (name)
- when "FU"
- PieceFU::new(self, x, y, sente)
- when "KY"
- PieceKY::new(self, x, y, sente)
- when "KE"
- PieceKE::new(self, x, y, sente)
- when "GI"
- PieceGI::new(self, x, y, sente)
- when "KI"
- PieceKI::new(self, x, y, sente)
- when "OU"
- PieceOU::new(self, x, y, sente)
- when "KA"
- PieceKA::new(self, x, y, sente)
- when "HI"
- PieceHI::new(self, x, y, sente)
- when "TO"
- PieceFU::new(self, x, y, sente, true)
- when "NY"
- PieceKY::new(self, x, y, sente, true)
- when "NK"
- PieceKE::new(self, x, y, sente, true)
- when "NG"
- PieceGI::new(self, x, y, sente, true)
- when "UM"
- PieceKA::new(self, x, y, sente, true)
- when "RY"
- PieceHI::new(self, x, y, sente, true)
- else
- raise "unkown piece #{name}"
- end
- end
- x = x - 1
- end
- elsif (str =~ /^P([\+\-])/)
- sg = $1
- if (sg == "+")
- sente = true
- else
- sente = false
- end
- str.sub!(/^../, '')
- while (str.length > 3)
- str.sub!(/^..(..)/, '')
- name = $1
- case (name)
- when "FU"
- PieceFU::new(self, 0, 0, sente)
- when "KY"
- PieceKY::new(self, 0, 0, sente)
- when "KE"
- PieceKE::new(self, 0, 0, sente)
- when "GI"
- PieceGI::new(self, 0, 0, sente)
- when "KI"
- PieceKI::new(self, 0, 0, sente)
- when "KA"
- PieceKA::new(self, 0, 0, sente)
- when "HI"
- PieceHI::new(self, 0, 0, sente)
- else
- raise "unkown piece #{name}"
- end
- end
- end
- end
- end
-end
-end
-