1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'observer_utils'
12 DuplicateUndoInformation = Class.new(Exception)
13 NoSuchPlayer = Class.new(Exception)
15 def initialize(players)
17 players.each do |player|
18 @players[player] = nil
22 def undo(player, moves, opts = { })
24 raise NoSuchPlayer unless @players.has_key?(player)
25 unless @players[player].nil?
26 raise DuplicateUndoInformation.new(
27 "player #{player.inspect} already specified undo information")
31 :more => opts[:allow_more] }
32 if @players.all?{|p, info| info }
34 fire :complete => common
35 fire :execute => common
51 @players.each do |player, data|
53 return nil unless data[:moves]
54 if common.nil? || data[:moves] > common
55 return nil unless common_more
57 common_more = data[:more]
58 elsif data[:moves] < common
59 return nil unless data[:more]