Commits

David Stone committed cafb3db

Made the function that converts a team to a string a free function instead of a member function.

Comments (0)

Files changed (5)

source/clients/battle.cpp

 	std::cout << std::string (20, '=') + '\n';
 	std::cout << "Predicting...\n";
 	Team predicted = predict_foe_team(detailed);
-	std::cout << predicted.to_string ();
+	std::cout << to_string(predicted) << '\n';
 
 	return expectiminimax(ai, predicted, weather, depth, evaluate, random_engine);
 }
 			call_move(foe, ai, weather, foe_variable, damage_is_known);
 		}
 	}
-	std::cout << first->to_string ();
-	std::cout << last->to_string ();
+	std::cout << to_string(*first) << '\n';
+	std::cout << to_string(*last) << '\n';
 }
 
 namespace {
 	return !(lhs == rhs);
 }
 
-std::string Team::to_string(bool const include_owner) const {
+std::string to_string(Team const & team, bool const include_owner) {
 	std::string output;
 	if (include_owner) {
-		output += who() + "'s team:\n";
+		output += team.who() + "'s team:\n";
 	}
-	for (auto const & member : all_pokemon()) {
+	for (auto const & member : team.all_pokemon()) {
 		output += member.to_string();
 		double const d_per_cent_hp = 100.0 * member.current_hp();
 		std::string const per_cent_hp = boost::lexical_cast <std::string> (boost::format ("%.1f") % d_per_cent_hp);
 		for (auto const stat : stats) {
 			add_stat(member.stat(stat.first), stat.second);
 		}
-		output += '\n';
 		member.move.for_each_regular_move([& output](Move const & move) {
-			output += "\t- " + move.to_string() + '\n';
+			output += "\n\t- " + move.to_string();
 		});
 	}
 	return output;
 	
 	typedef uint64_t hash_type;
 	hash_type hash () const;
-	std::string to_string(bool include_owner = true) const;
 	friend bool operator== (Team const & lhs, Team const & rhs);
 
 private:
 };
 bool operator!= (Team const & lhs, Team const & rhs);
 
+std::string to_string(Team const & team, bool include_owner = true);
+
 }	// namespace technicalmachine
 #endif	// TEAM_HPP_

source/team_predictor/predictor.cpp

 	}
 	generate_random_team(data);
 	Team team = predict_team(data.detailed, data.team(), data.random_engine, using_lead);
-	data.output->value(team.to_string(false).c_str());
+	data.output->value(to_string(team, false).c_str());
 	data.reset();
 }
 

source/test/ev_optimizer.cpp

 	pokemon.calculate_initial_hp();
 	pokemon.move.add(Moves::Psychic, 3);
 	pokemon.move.add(Moves::Earthquake, 3);
-	std::cerr << "Before: " << '\n' << team.to_string(false) << '\n';
+//	std::cerr << "Before: " << '\n' << team.to_string(false) << '\n';
 	minimize_evs(team.pokemon());
-	std::cerr << "After: " << '\n' << team.to_string(false) << '\n';
+//	std::cerr << "After: " << '\n' << team.to_string(false) << '\n';
 	std::random_device rd;
 	std::mt19937 random_engine(rd());
 	pad_random_evs(team.pokemon(), random_engine);
-	std::cerr << "Final: " << '\n' << team.to_string(false) << '\n';
+//	std::cerr << "Final: " << '\n' << team.to_string(false) << '\n';
 }
 
 }	// namespace technicalmachine