Skip to content
Browse files

Implement members collection for infosets.

  • Loading branch information...
1 parent c3808d3 commit 36dbc7df225ab291c5564c3ef501abd0331c2510 @tturocy tturocy committed Jul 29, 2011
Showing with 27 additions and 2 deletions.
  1. +8 −1 src/python/gambit/lib/infoset.pxi
  2. +3 −1 src/python/gambit/lib/libgambit.pyx
  3. +16 −0 src/python/gambit/lib/members.pxi
View
9 src/python/gambit/lib/infoset.pxi
@@ -39,4 +39,11 @@ cdef class Infoset:
cdef Actions a
a = Actions()
a.infoset = self.infoset
- return a
+ return a
+
+ property members:
+ def __get__(self):
+ cdef Members m
+ m = Members()
+ m.infoset = self.infoset
+ return m
View
4 src/python/gambit/lib/libgambit.pyx
@@ -72,6 +72,8 @@ cdef extern from "libgambit/game.h":
int NumActions()
c_GameAction GetAction(int) except +IndexError
+ int NumMembers()
+ c_GameNode GetMember(int) except +IndexError
ctypedef struct c_GamePlayerRep "GamePlayerRep":
c_Game GetGame()
@@ -168,7 +170,7 @@ include "strategies.pxi"
include "action.pxi"
include "actions.pxi"
-
+include "members.pxi"
include "infoset.pxi"
include "infosets.pxi"
View
16 src/python/gambit/lib/members.pxi
@@ -0,0 +1,16 @@
+cdef class Members:
+ cdef c_GameInfoset infoset
+
+ def __repr__(self):
+ return str(list(self))
+
+ def __len__(self):
+ return self.infoset.deref().NumMembers()
+
+ def __getitem__(self, i):
+ cdef Node n
+ if i < 0 or i >= len(self):
+ raise IndexError("no member with index '%s'" % i)
+ n = Node()
+ n.node = self.infoset.deref().GetMember(i+1)
+ return n

0 comments on commit 36dbc7d

Please sign in to comment.
Something went wrong with that request. Please try again.