1 require 'observer_utils.rb'
9 Item = Struct.new(:state, :move)
10 OutOfBound = Class.new(Exception)
13 @history = [Item.new(state.dup, nil)]
18 @history.each {|item| yield item.state, item.move }
21 def add_move(state, move)
22 item = Item.new(state.dup, move)
23 @history = @history[0..@current]
25 @current = @history.size - 1
29 raise OutOfBound if @current >= @history.size - 1
31 item = @history[@current]
32 [item.state, item.move]
36 raise OutOfBound if @current <= 0
37 move = @history[@current].move
39 [@history[@current].state, move]
43 @history[current].state
47 @history[current].move