@@ -50,54 +50,42 @@ GameExplicitRep::~GameExplicitRep()
5050// GameExplicitRep: General data access
5151// ------------------------------------------------------------------------
5252
53- Rational GameExplicitRep::GetMinPayoff (int player ) const
53+ Rational GameExplicitRep::GetMinPayoff () const
5454{
55- int p1, p2;
55+ return std::accumulate (
56+ std::next (m_players.begin ()), m_players.end (), GetMinPayoff (m_players.front ()),
57+ [this ](const Rational &r, const GamePlayer &p) { return std::min (r, GetMinPayoff (p)); });
58+ }
5659
60+ Rational GameExplicitRep::GetMinPayoff (const GamePlayer &p_player) const
61+ {
5762 if (m_outcomes.empty ()) {
5863 return Rational (0 );
5964 }
60-
61- if (player) {
62- p1 = p2 = player;
63- }
64- else {
65- p1 = 1 ;
66- p2 = NumPlayers ();
67- }
68-
69- Rational minpay = m_outcomes.front ()->GetPayoff <Rational>(GetPlayer (p1));
70- for (auto outcome : m_outcomes) {
71- for (int p = p1; p <= p2; p++) {
72- minpay = std::min (minpay, outcome->GetPayoff <Rational>(GetPlayer (p)));
73- }
74- }
75- return minpay;
65+ return std::accumulate (std::next (m_outcomes.begin ()), m_outcomes.end (),
66+ m_outcomes.front ()->GetPayoff <Rational>(p_player),
67+ [&p_player](const Rational &r, const GameOutcomeRep *c) {
68+ return std::min (r, c->GetPayoff <Rational>(p_player));
69+ });
7670}
7771
78- Rational GameExplicitRep::GetMaxPayoff (int player ) const
72+ Rational GameExplicitRep::GetMaxPayoff () const
7973{
80- int p1, p2;
74+ return std::accumulate (
75+ std::next (m_players.begin ()), m_players.end (), GetMaxPayoff (m_players.front ()),
76+ [this ](const Rational &r, const GamePlayer &p) { return std::max (r, GetMaxPayoff (p)); });
77+ }
8178
79+ Rational GameExplicitRep::GetMaxPayoff (const GamePlayer &p_player) const
80+ {
8281 if (m_outcomes.empty ()) {
8382 return Rational (0 );
8483 }
85-
86- if (player) {
87- p1 = p2 = player;
88- }
89- else {
90- p1 = 1 ;
91- p2 = NumPlayers ();
92- }
93-
94- Rational maxpay = m_outcomes.front ()->GetPayoff <Rational>(GetPlayer (p1));
95- for (auto outcome : m_outcomes) {
96- for (int p = p1; p <= p2; p++) {
97- maxpay = std::max (maxpay, outcome->GetPayoff <Rational>(GetPlayer (p)));
98- }
99- }
100- return maxpay;
84+ return std::accumulate (std::next (m_outcomes.begin ()), m_outcomes.end (),
85+ m_outcomes.front ()->GetPayoff <Rational>(p_player),
86+ [&p_player](const Rational &r, const GameOutcomeRep *c) {
87+ return std::max (r, c->GetPayoff <Rational>(p_player));
88+ });
10189}
10290
10391// ------------------------------------------------------------------------
0 commit comments