class Shogi::Game
Attributes
default_format[RW]
turn[R]
Public Class Methods
new(format=:csa, turn="+")
click to toggle source
# File lib/shogi/game.rb, line 5 def initialize(format=:csa, turn="+") raise ArgumentError, "Undefined format: #{format}" unless /\Acsa\z/ =~ format raise ArgumentError, "Invalid turn: #{turn}" unless /\A[+-]\z/ =~ turn @default_format = format @board = Shogi::Board.new(@default_format) @turn = turn @kifu = [] end
Public Instance Methods
at(num_of_moves)
click to toggle source
# File lib/shogi/game.rb, line 49 def at(num_of_moves) Shogi::Game.new.move(@kifu[0, num_of_moves].join("\n") << "\n") end
kifu()
click to toggle source
# File lib/shogi/game.rb, line 36 def kifu @kifu.join("\n") << "\n" end
move(movement_lines, format=@default_format)
click to toggle source
# File lib/shogi/game.rb, line 26 def move(movement_lines, format=@default_format) movement_lines.each_line do |movement| movement.chomp! @board.move(movement, format) @kifu << movement @turn = (@turn == "+") ? "-" : "+" end self end
show(format=@default_format)
click to toggle source
# File lib/shogi/game.rb, line 40 def show(format=@default_format) $stdout.puts __send__("to_#{format}") end
show_all(format=@default_format)
click to toggle source
# File lib/shogi/game.rb, line 44 def show_all(format=@default_format) show $stdout.puts kifu end
to_csa()
click to toggle source
# File lib/shogi/game.rb, line 15 def to_csa @board.to_csa << turn << "\n" end
to_usi()
click to toggle source
# File lib/shogi/game.rb, line 19 def to_usi t = @turn == '+' ? 'b' : 'w' next_num = @kifu.size + 1 @board.to_usi.chomp + " #{t} #{@board.usi_captured} #{next_num}" end
Also aliased as: to_sfen