forked from gambitproject/gambit
/
strategy.pxi
35 lines (31 loc) · 1.27 KB
/
strategy.pxi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
cdef class Strategy:
cdef c_GameStrategy strategy
def __repr__(self):
return "<Strategy [%d] '%s' for player '%s' in game '%s'>" % \
(self.strategy.deref().GetNumber()-1, self.label,
self.strategy.deref().GetPlayer().deref().GetLabel().c_str(),
self.strategy.deref().GetPlayer().deref().GetGame().deref().GetTitle().c_str())
def __richcmp__(Strategy self, other, whichop):
if isinstance(other, Strategy):
if whichop == 2:
return self.strategy.deref() == ((<Strategy>other).strategy).deref()
elif whichop == 3:
return self.strategy.deref() != ((<Strategy>other).strategy).deref()
else:
raise NotImplementedError
else:
if whichop == 2:
return False
elif whichop == 3:
return True
else:
raise NotImplementedError
def __hash__(self):
return long(<long>self.strategy.deref())
property label:
def __get__(self):
return self.strategy.deref().GetLabel().c_str()
def __set__(self, char *value):
cdef cxx_string s
s.assign(value)
self.strategy.deref().SetLabel(s)