Esempio n. 1
0
void tod_manager::resolve_random(random_new::rng& r)
{
	//process the random_start_time string, which can be boolean yes/no true/false or a
	//comma-separated string of integers >= 1 referring to the times_ array indices
	std::vector<std::string> output_strings = utils::split(random_tod_.str());
	std::vector<int> output;

	try
	{
		std::transform(output_strings.begin(), output_strings.end(), std::back_inserter(output),
			[](const std::string& str)
		{
			return std::stoi(str);
		});
	}
	catch (std::invalid_argument)
	{
		// This happens if the random_start_time string is a boolean.
		// Simply ignore the exception.
	}

	// Remove non-positive times
	output.erase(
		std::remove_if(
			output.begin(),
			output.end(),
			[](int time){ return time <= 0; }),
		output.end());

	if(!output.empty())
	{
		int chosen = output[r.next_random() % output.size()];
		currentTime_ = calculate_current_time(times_.size(), turn_, chosen, true);
		r.next_random();
	}
	else if (random_tod_.to_bool(false))
	{
		currentTime_ = calculate_current_time(times_.size(), turn_, r.next_random(), true);
	}
	random_tod_ = false;
}
Esempio n. 2
0
void tod_manager::resolve_random(random_new::rng& r)
{
	//process the random_start_time string, which can be boolean yes/no true/false or a
	//comma-separated string of integers >= 1 referring to the times_ array indices
	std::vector<int> output;
	boost::copy( utils::split(random_tod_.str())
		| boost::adaptors::transformed(boost::bind(lexical_cast_default<int, std::string>, _1 , 0))
		| boost::adaptors::filtered(greater<int>(0))
		, std::back_inserter(output) );

	if(!output.empty())
	{
		int chosen = output[r.next_random() % output.size()];
		currentTime_ = calculate_current_time(times_.size(), turn_, chosen, true);
		r.next_random();
	}
	else if (random_tod_.to_bool(false))
	{
		currentTime_ = calculate_current_time(times_.size(), turn_, r.next_random(), true);
	}
	random_tod_ = false;
}