1from pychess.Utils.const import ACTIONS 2 3 4def cmp(x, y): 5 return (x > y) - (x < y) 6 7 8class Offer: 9 def __init__(self, type_, param=None, index=None): 10 assert type_ in ACTIONS, "Offer.__init__(): type not in ACTIONS: %s" % repr( 11 type_) 12 assert index is None or isinstance(index, int), \ 13 "Offer.__init__(): index not int: %s" % repr(index) 14 self.type = type_ 15 self.param = param 16 self.index = index # for IC games 17 18 def __hash__(self): 19 return hash((self.type, self.param, self.index)) 20 21 def __cmp__(self, other): 22 assert isinstance( 23 other, 24 type(self)), "Offer.__cmp__(): not of type Offer: %s" % repr(other) 25 return cmp(hash(self), hash(other)) 26 27 def __repr__(self): 28 text = "type=\"%s\"" % self.type 29 if self.param is not None: 30 text += ", param=%s" % str(self.param) 31 if self.index is not None: 32 text += ", index=%s" % str(self.index) 33 return "Offer(" + text + ")" 34