# i -> 9
def alphabetToDan(s)
if RUBY_VERSION >= "1.9.1"
- return s.bytes[0]-96
+ # String.bytes is incompatible:
+ # - Ruby 1.9.3 String.bytes returns Enumerator
+ # - Ruby 2.1.0 String.bytes returns [Integer]
+ return s.each_byte.next-96
else
return s[0]-96
end
# Convert USI moves to CSA one by one from the initial position
#
class UsiToCsa
- attr_reader :board, :csa_moves
+ attr_reader :board, :csa_moves, :usi_moves
# Constructor
#
@board.initial
@sente = true
@csa_moves = []
+ @usi_moves = []
+ end
+
+ def deep_copy
+ return Marshal.load(Marshal.dump(self))
end
# Parses a usi move string and returns an array of [move_result_state,
# csa_move_string]
#
def next(usi)
+ usi_moves << usi
csa = Usi.usiToCsa(usi, @board, @sente)
state = @board.handle_one_move(csa, @sente)
@sente = !@sente
@csa_moves << csa
return [state, csa]
end
+
end # class UsiToCsa
# Convert CSA moves to USI one by one from the initial position
#
class CsaToUsi
- attr_reader :board, :usi_moves
+ attr_reader :board, :csa_moves, :usi_moves
# Constructor
#
@board = ShogiServer::Board.new
@board.initial
@sente = true
+ @csa_moves = []
@usi_moves = []
end
+ def deep_copy
+ return Marshal.load(Marshal.dump(self))
+ end
+
# Parses a csa move string and returns an array of [move_result_state,
# usi_move_string]
#
def next(csa)
+ csa_moves << csa
state = @board.handle_one_move(csa, @sente)
@sente = !@sente
usi = Usi.moveToUsi(@board.move)