@@ -123,8 +123,8 @@ void GamePlayerRep::MakeStrategy()
123123 Array<int > c (NumInfosets ());
124124
125125 for (int i = 1 ; i <= NumInfosets (); i++) {
126- if (m_infosets[i]->flag == 1 ) {
127- c[i] = m_infosets[i]->whichbranch ;
126+ if (m_infosets[i - 1 ]->flag == 1 ) {
127+ c[i] = m_infosets[i - 1 ]->whichbranch ;
128128 }
129129 else {
130130 c[i] = 0 ;
@@ -219,7 +219,7 @@ void GamePlayerRep::MakeReducedStrats(GameTreeNodeRep *n, GameTreeNodeRep *nn)
219219 }
220220}
221221
222- GameInfoset GamePlayerRep::GetInfoset (int p_index) const { return m_infosets[p_index]; }
222+ GameInfoset GamePlayerRep::GetInfoset (int p_index) const { return m_infosets[p_index - 1 ]; }
223223
224224Array<GameInfoset> GamePlayerRep::GetInfosets () const
225225{
@@ -400,46 +400,31 @@ template <class T>
400400MixedStrategyProfile<T>::MixedStrategyProfile(const MixedBehaviorProfile<T> &p_profile)
401401 : m_rep(new TreeMixedStrategyProfileRep<T>(p_profile))
402402{
403- Game game = p_profile.GetGame ();
404- auto *efg = dynamic_cast <GameTreeRep *>(game.operator ->());
405- for (int pl = 1 ; pl <= m_rep->m_support .GetGame ()->NumPlayers (); pl++) {
406- GamePlayer player = m_rep->m_support .GetGame ()->GetPlayer (pl);
407- for (int st = 1 ; st <= player->NumStrategies (); st++) {
408- T prob = (T)1 ;
409-
410- for (int iset = 1 ; iset <= efg->GetPlayer (pl)->NumInfosets (); iset++) {
411- if (efg->m_players [pl]->m_strategies [st]->m_behav [iset] > 0 ) {
412- GameInfoset infoset = player->GetInfoset (iset);
413- prob *=
414- p_profile[infoset->GetAction (efg->m_players [pl]->m_strategies [st]->m_behav [iset])];
403+ auto *efg = dynamic_cast <GameTreeRep *>(p_profile.GetGame ().operator ->());
404+ for (const auto &player : efg->m_players ) {
405+ for (const auto &strategy : player->m_strategies ) {
406+ auto prob = static_cast <T>(1 );
407+ for (const auto &infoset : player->m_infosets ) {
408+ if (strategy->m_behav [infoset->GetNumber ()] > 0 ) {
409+ prob *= p_profile[infoset->GetAction (strategy->m_behav [infoset->GetNumber ()])];
415410 }
416411 }
417- (*this )[ m_rep-> m_support . GetGame ()-> GetPlayer (pl)-> GetStrategy (st) ] = prob;
412+ (*m_rep)[strategy ] = prob;
418413 }
419414 }
420415}
421416
422- template <class T >
423- MixedStrategyProfile<T>::MixedStrategyProfile(const MixedStrategyProfile<T> &p_profile)
424- : m_rep(p_profile.m_rep->Copy ())
425- {
426- InvalidateCache ();
427- }
428-
429417template <class T >
430418MixedStrategyProfile<T> &
431419MixedStrategyProfile<T>::operator =(const MixedStrategyProfile<T> &p_profile)
432420{
433421 if (this != &p_profile) {
434422 InvalidateCache ();
435- delete m_rep;
436- m_rep = p_profile.m_rep ->Copy ();
423+ m_rep.reset (p_profile.m_rep ->Copy ());
437424 }
438425 return *this ;
439426}
440427
441- template <class T > MixedStrategyProfile<T>::~MixedStrategyProfile () { delete m_rep; }
442-
443428// ========================================================================
444429// MixedStrategyProfile<T>: General data access
445430// ========================================================================
@@ -449,10 +434,8 @@ template <class T> Vector<T> MixedStrategyProfile<T>::operator[](const GamePlaye
449434 CheckVersion ();
450435 auto strategies = m_rep->m_support .GetStrategies (p_player);
451436 Vector<T> probs (strategies.size ());
452- int st = 1 ;
453- for (auto strategy : strategies) {
454- probs[st] = (*this )[strategy];
455- }
437+ std::transform (strategies.begin (), strategies.end (), probs.begin (),
438+ [this ](const GameStrategy &s) { return (*m_rep)[s]; });
456439 return probs;
457440}
458441
@@ -461,9 +444,10 @@ template <class T> MixedStrategyProfile<T> MixedStrategyProfile<T>::ToFullSuppor
461444 CheckVersion ();
462445 MixedStrategyProfile<T> full (m_rep->m_support .GetGame ()->NewMixedStrategyProfile (T (0 )));
463446
464- for (auto player : m_rep->m_support .GetGame ()->GetPlayers ()) {
465- for (auto strategy : player->GetStrategies ()) {
466- full[strategy] = (m_rep->m_support .Contains (strategy)) ? (*this )[strategy] : T (0 );
447+ for (const auto &player : m_rep->m_support .GetGame ()->GetPlayers ()) {
448+ for (const auto &strategy : player->GetStrategies ()) {
449+ full[strategy] =
450+ (m_rep->m_support .Contains (strategy)) ? (*m_rep)[strategy] : static_cast <T>(0 );
467451 }
468452 }
469453 return full;
@@ -472,17 +456,18 @@ template <class T> MixedStrategyProfile<T> MixedStrategyProfile<T>::ToFullSuppor
472456// ========================================================================
473457// MixedStrategyProfile<T>: Computation of interesting quantities
474458// ========================================================================
459+
475460template <class T > void MixedStrategyProfile<T>::ComputePayoffs() const
476461{
477462 if (!map_profile_payoffs.empty ()) {
478463 // caches (map_profile_payoffs and map_strategy_payoffs) are valid,
479464 // so don't compute anything, simply return
480465 return ;
481466 }
482- for (auto player : m_rep->m_support .GetPlayers ()) {
467+ for (const auto & player : m_rep->m_support .GetPlayers ()) {
483468 map_profile_payoffs[player] = GetPayoff (player);
484469 // values of the player's strategies
485- for (auto strategy : m_rep->m_support .GetStrategies (player)) {
470+ for (const auto & strategy : m_rep->m_support .GetStrategies (player)) {
486471 map_strategy_payoffs[player][strategy] = GetPayoff (strategy);
487472 }
488473 }
@@ -493,13 +478,10 @@ template <class T> T MixedStrategyProfile<T>::GetLiapValue() const
493478 CheckVersion ();
494479 ComputePayoffs ();
495480
496- T liapValue = T (0 );
497- for (auto player : m_rep-> m_support . GetPlayers () ) {
481+ auto liapValue = static_cast <T> (0 );
482+ for (auto [ player, payoff] : map_profile_payoffs ) {
498483 for (auto v : map_strategy_payoffs[player]) {
499- T regret = v.second - map_profile_payoffs[player];
500- if (regret > T (0 )) {
501- liapValue += regret * regret; // penalty if not best response
502- }
484+ liapValue += sqr (std::max (v.second - payoff, static_cast <T>(0 )));
503485 }
504486 }
505487 return liapValue;
0 commit comments