Class: Shogi::Board
- Inherits:
-
Object
- Object
- Shogi::Board
- Defined in:
- lib/shogi/board.rb
Instance Attribute Summary collapse
-
#default_format ⇒ Object
Returns the value of attribute default_format.
-
#validate_movement ⇒ Object
Returns the value of attribute validate_movement.
Class Method Summary collapse
Instance Method Summary collapse
- #at(place) ⇒ Object
-
#initialize(default_format = :csa, table = nil) ⇒ Board
constructor
A new instance of Board.
- #move(movement_lines, format = @default_format) ⇒ Object
- #set_from_csa(csa) ⇒ Object
- #show(format = @default_format) ⇒ Object
Constructor Details
#initialize(default_format = :csa, table = nil) ⇒ Board
Returns a new instance of Board.
21 22 23 24 25 |
# 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 |
Instance Attribute Details
#default_format ⇒ Object
Returns the value of attribute default_format.
19 20 21 |
# File 'lib/shogi/board.rb', line 19 def default_format @default_format end |
#validate_movement ⇒ Object
Returns the value of attribute validate_movement.
20 21 22 |
# File 'lib/shogi/board.rb', line 20 def validate_movement @validate_movement end |
Class Method Details
.register(name) ⇒ Object
13 14 15 |
# File 'lib/shogi/board.rb', line 13 def self.register(name) send(:include, Format.const_get(name).const_get("Board")) end |
Instance Method Details
#at(place) ⇒ Object
39 40 41 42 43 |
# 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) ⇒ Object
31 32 33 34 35 36 37 |
# 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) ⇒ Object
27 28 29 |
# File 'lib/shogi/board.rb', line 27 def set_from_csa(csa) @table, @captured = parse_from_csa(csa) end |
#show(format = @default_format) ⇒ Object
45 46 47 |
# File 'lib/shogi/board.rb', line 45 def show(format=@default_format) $stdout.puts __send__("to_#{format}") end |