@@ -121,7 +121,7 @@ class GameOutcomeRep : public GameObject {
121121 GameRep *m_game;
122122 int m_number;
123123 std::string m_label;
124- Array< Number> m_payoffs;
124+ std::map<GamePlayerRep *, Number> m_payoffs;
125125
126126 // / @name Lifecycle
127127 // @{
@@ -145,7 +145,6 @@ class GameOutcomeRep : public GameObject {
145145
146146 // / Gets the payoff associated with the outcome to the player
147147 template <class T > const T &GetPayoff (const GamePlayer &p_player) const ;
148-
149148 // / Sets the payoff to the player
150149 void SetPayoff (const GamePlayer &p_player, const Number &p_value);
151150 // @}
@@ -586,27 +585,31 @@ inline Game GameOutcomeRep::GetGame() const { return m_game; }
586585
587586template <class T > const T &GameOutcomeRep::GetPayoff (const GamePlayer &p_player) const
588587{
589- if (p_player->GetGame () != GetGame ()) {
588+ try {
589+ return static_cast <const T &>(m_payoffs.at (p_player));
590+ }
591+ catch (const std::out_of_range &) {
590592 throw MismatchException ();
591593 }
592- return static_cast <const T &>(m_payoffs[p_player->GetNumber ()]);
593594}
594595
595596template <> inline const Number &GameOutcomeRep::GetPayoff (const GamePlayer &p_player) const
596597{
597- if (p_player->GetGame () != GetGame ()) {
598+ try {
599+ return m_payoffs.at (p_player);
600+ }
601+ catch (const std::out_of_range &) {
598602 throw MismatchException ();
599603 }
600- return m_payoffs[p_player->GetNumber ()];
601604}
602605
603606inline void GameOutcomeRep::SetPayoff (const GamePlayer &p_player, const Number &p_value)
604607{
605608 if (p_player->GetGame () != GetGame ()) {
606609 throw MismatchException ();
607610 }
611+ m_payoffs[p_player] = p_value;
608612 m_game->IncrementVersion ();
609- m_payoffs[p_player->GetNumber ()] = p_value;
610613}
611614
612615inline GamePlayer GameStrategyRep::GetPlayer () const { return m_player; }
0 commit comments