class Shogi::Board
Attributes
default_format[RW]
validate_movement[RW]
Public Class Methods
new(default_format=:csa, table=nil)
click to toggle source
# File lib/shogi/board.rb, line 21 def initialize(default_format=:csa, table=nil) @default_format = default_format set_from_csa(table || default_table) @validate_movement = true end
register(name)
click to toggle source
# File lib/shogi/board.rb, line 13 def self.register(name) send(:include, Format.const_get(name).const_get("Board")) end
Public Instance Methods
at(place)
click to toggle source
# File lib/shogi/board.rb, line 39 def at(place) array_x = to_array_x_from_shogi_x(place[0].to_i) array_y = to_array_y_from_shogi_y(place[1].to_i) @table[array_y][array_x] end
move(movement_lines, format=@default_format)
click to toggle source
# File lib/shogi/board.rb, line 31 def move(movement_lines, format=@default_format) movement_lines.each_line do |movement| movement.chomp! __send__("move_by_#{format.to_s}", movement) end self end
set_from_csa(csa)
click to toggle source
# File lib/shogi/board.rb, line 27 def set_from_csa(csa) @table, @captured = parse_from_csa(csa) end
show(format=@default_format)
click to toggle source
# File lib/shogi/board.rb, line 45 def show(format=@default_format) $stdout.puts __send__("to_#{format}") end
Private Instance Methods
default_table()
click to toggle source
# File lib/shogi/board.rb, line 50 def default_table <<-TABLE P1-KY-KE-GI-KI-OU-KI-GI-KE-KY P2 * -HI * * * * * -KA * P3-FU-FU-FU-FU-FU-FU-FU-FU-FU P4 * * * * * * * * * P5 * * * * * * * * * P6 * * * * * * * * * P7+FU+FU+FU+FU+FU+FU+FU+FU+FU P8 * +KA * * * * * +HI * P9+KY+KE+GI+KI+OU+KI+GI+KE+KY P+ P- TABLE end
raise_movement_error(message)
click to toggle source
# File lib/shogi/board.rb, line 66 def raise_movement_error(message) if @validate_movement raise MovementError, message end end
to_array_x_from_shogi_x(shogi_x)
click to toggle source
# File lib/shogi/board.rb, line 72 def to_array_x_from_shogi_x(shogi_x) 9 - shogi_x end
to_array_y_from_shogi_y(shogi_y)
click to toggle source
# File lib/shogi/board.rb, line 76 def to_array_y_from_shogi_y(shogi_y) shogi_y - 1 end
to_shogi_x_from_array_x(array_x)
click to toggle source
# File lib/shogi/board.rb, line 80 def to_shogi_x_from_array_x(array_x) 9 - array_x end
to_shogi_y_from_array_y(array_y)
click to toggle source
# File lib/shogi/board.rb, line 84 def to_shogi_y_from_array_y(array_y) array_y + 1 end