Skip to content

Commit 24bb91e

Browse files
tturocyd-kad
authored andcommitted
Expose access to action map for a strategy
This provides a crude interface to the mapping from infoset to action as part of a strategy for an extensive game. A function `.action()` has been added in Python as well. This is not a final polished interface for this information, just a starter to enable work on issue 440.
1 parent 16714f0 commit 24bb91e

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

src/games/game.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ GameOutcomeRep::GameOutcomeRep(GameRep *p_game, int p_number) : m_game(p_game),
4646
}
4747
}
4848

49+
//========================================================================
50+
// class GameStrategyRep
51+
//========================================================================
52+
53+
GameAction GameStrategyRep::GetAction(const GameInfoset &p_infoset) const
54+
{
55+
if (p_infoset->GetPlayer() != m_player) {
56+
throw MismatchException();
57+
}
58+
int action = m_behav[p_infoset->GetNumber()];
59+
return (action) ? *std::next(p_infoset->GetActions().cbegin(), action - 1) : nullptr;
60+
}
61+
62+
void GameStrategyRep::DeleteStrategy()
63+
{
64+
if (m_player->GetGame()->IsTree()) {
65+
throw UndefinedException();
66+
}
67+
}
68+
4969
//========================================================================
5070
// class GamePlayerRep
5171
//========================================================================

src/games/game.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ class GameStrategyRep : public GameObject {
358358
GamePlayer GetPlayer() const;
359359
/// Returns the index of the strategy for its player
360360
int GetNumber() const { return m_number; }
361+
362+
/// Returns the action specified by the strategy at the information set
363+
GameAction GetAction(const GameInfoset &) const;
364+
365+
/// Remove this strategy from the game
366+
void DeleteStrategy();
361367
//@}
362368
};
363369

src/pygambit/gambit.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ cdef extern from "games/game.h":
9797
c_GamePlayer GetPlayer() except +
9898
string GetLabel() except +
9999
void SetLabel(string) except +
100+
c_GameAction GetAction(c_GameInfoset) except +
101+
void DeleteStrategy() except +
100102

101103
cdef cppclass c_GameActionRep "GameActionRep":
102104
int GetNumber() except +

src/pygambit/strategy.pxi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@ class Strategy:
7373
def number(self) -> int:
7474
"""The number of the strategy."""
7575
return self.strategy.deref().GetNumber() - 1
76+
77+
def action(self, infoset: Infoset) -> Action:
78+
return Action.wrap(self.strategy.deref().GetAction(infoset.infoset))

0 commit comments

Comments
 (0)