Sha256: 03254f3cf455e9fbfca4136b311cddf040e610d6627af12b25b5f5775b11e4f2
Contents?: true
Size: 1.05 KB
Versions: 5
Compression:
Stored size: 1.05 KB
Contents
module Shogi class Game attr_accessor :default_format attr_reader :turn 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 def to_csa @board.to_csa << turn << "\n" end 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 def kifu @kifu.join("\n") << "\n" end def show(format=@default_format) $stdout.puts __send__("to_#{format}") end def show_all(format=@default_format) show $stdout.puts kifu end def at(num_of_moves) Shogi::Game.new.move(@kifu[0, num_of_moves].join("\n") << "\n") end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
shogi-ruby-0.0.9 | lib/shogi/game.rb |
shogi-ruby-0.0.8 | lib/shogi/game.rb |
shogi-ruby-0.0.7 | lib/shogi/game.rb |
shogi-ruby-0.0.6 | lib/shogi/game.rb |
shogi-ruby-0.0.5 | lib/shogi/game.rb |