Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(UI): add iteration config for item group debug spawn test #5875

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3467,15 +3467,27 @@ void item_group::debug_spawn()
for( size_t i = 0; i < groups.size(); i++ ) {
menu.entries.emplace_back( static_cast<int>( i ), true, -2, groups[i].str() );
}
uilist iter_config;
iter_config.text = _( "How many iterations to test?" );
constexpr std::array<size_t, 4> iter_choices = { 10, 100, 1000, 10000 };
for( size_t i = 0; i < iter_choices.size(); i++ ) {
iter_config.entries.emplace_back( static_cast<int>( i ), true, -2,
std::to_string( iter_choices[i] ) );
}
while( true ) {
menu.query();
const int index = menu.ret;
if( index >= static_cast<int>( groups.size() ) || index < 0 ) {
break;
}
iter_config.query();
const int iter_index = iter_config.ret;
if( iter_index >= static_cast<int>( iter_choices.size() ) || iter_index < 0 ) {
break;
}
// Spawn items from the group 100 times
std::map<std::string, int> itemnames;
for( size_t a = 0; a < 100; a++ ) {
for( size_t a = 0; a < iter_choices[iter_index]; a++ ) {
const auto items = items_from( groups[index], calendar::turn );
for( auto &it : items ) {
itemnames[it->display_name()]++;
Expand All @@ -3487,7 +3499,7 @@ void item_group::debug_spawn()
itemnames2.insert( std::pair<int, std::string>( e.second, e.first ) );
}
uilist menu2;
menu2.text = _( "Result of 100 spawns:" );
menu2.text = string_format( _( "Results of %zu spawns:" ), iter_choices[iter_index] );
for( const auto &e : itemnames2 ) {
menu2.entries.emplace_back( static_cast<int>( menu2.entries.size() ), true, -2,
string_format( _( "%d x %s" ), e.first, e.second ) );
Expand Down
Loading