1 require 'observer_utils.rb'
9 Item = Struct.new(:state, :move, :text)
10 OutOfBound = Class.new(Exception)
13 @history = [Item.new(state.dup, nil, "Mainline")]
18 @history.each {|item| yield item.state, item.move }
21 def add_move(state, move)
22 item = Item.new(state.dup, move, nil)
23 old_size = @history.size
25 @history = @history[0..@current]
28 @current = @history.size - 1
34 raise OutOfBound if @current >= @history.size - 1
36 item = @history[@current]
39 [item.state, item.move]
43 raise OutOfBound if @current <= 0
44 move = @history[@current].move
48 [@history[@current].state, move]
55 [item.state, item.move]
59 @history[current].state
63 @history[current].move
71 if index >= @history.size || index < 0