change m_players in GameRep from Array to std::vector#510
Closed
d-kad wants to merge 1 commit intogambitproject:masterfrom
Closed
change m_players in GameRep from Array to std::vector#510d-kad wants to merge 1 commit intogambitproject:masterfrom
d-kad wants to merge 1 commit intogambitproject:masterfrom
Conversation
tturocy
requested changes
Apr 22, 2025
Member
tturocy
left a comment
There was a problem hiding this comment.
There are some opportunities here for taking care of some C++ modernisation - including ways to get rid of a lot of the index-based expressions altogether.
| { | ||
| Array<int> ns; | ||
| for (int pl = 1; pl <= aggPtr->getNumPlayers(); pl++) { | ||
| ns.push_back(m_players[pl]->NumStrategies()); |
Member
There was a problem hiding this comment.
Here is a good opportunity to modernise code by avoiding the use of indices altogether:
for (const auto &player : m_players) {
ns.push_back(player->NumStrategies());
}
src/games/gameagg.cc
Outdated
|
|
||
| GameStrategy GameAGGRep::GetStrategy(int p_index) const | ||
| { | ||
| for (int pl = 1; pl <= aggPtr->getNumPlayers(); pl++) { |
Member
There was a problem hiding this comment.
Can also be written as a range-based for-loop (as above example)
src/games/gamebagg.cc
Outdated
| @@ -246,7 +246,7 @@ int GameBAGGRep::MixedProfileLength() const | |||
| { | |||
| int res = 0; | |||
| for (size_t pl = 1; pl <= NumPlayers(); pl++) { | |||
Member
There was a problem hiding this comment.
Range-based for loop - or arguably even better std::aggregate to use an STL algorithm.
Contributor
Author
There was a problem hiding this comment.
I went for the range-based option as the alternative code (using std::accumulate) looked too bulky and complex
Member
|
Merged at 58f66f5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #496