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
Added useful metrics #168
Added useful metrics #168
Changes from 7 commits
3f7862a
a5d61e0
1f8ed06
9d3e2ba
65cd5a3
6b99a4f
8d7a44a
44ff82b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,18 +50,24 @@ void to_json(nlohmann::json &json, const PlayerStatistics &stats) { | |
FIELD_TO_JSON(random_id), | ||
FIELD_TO_JSON(rank), | ||
FIELD_TO_JSON(last_turn_alive), | ||
FIELD_TO_JSON(last_turn_ship_spawn), | ||
{"final_production", final_production}, | ||
FIELD_TO_JSON(total_production), | ||
FIELD_TO_JSON(max_entity_distance), | ||
FIELD_TO_JSON(number_dropoffs), | ||
FIELD_TO_JSON(interaction_opportunities), | ||
FIELD_TO_JSON(ships_captured), | ||
FIELD_TO_JSON(ships_given), | ||
//FIELD_TO_JSON(ships_captured), | ||
//FIELD_TO_JSON(ships_given), | ||
FIELD_TO_JSON(ships_spawned), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we're at it, we should stop writing unused fields - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually specifically advised against that on discord. But after thinking about it some more the risk seems very minimal and while the benefit is also fairly small it probably is good on balance. Since you're obviously in favor, I'm fine with them going as well. |
||
FIELD_TO_JSON(ships_peak), | ||
FIELD_TO_JSON(self_collisions), | ||
FIELD_TO_JSON(all_collisions), | ||
FIELD_TO_JSON(dropoff_collisions), | ||
FIELD_TO_JSON(total_mined), | ||
FIELD_TO_JSON(total_bonus), | ||
FIELD_TO_JSON(total_mined_from_captured), | ||
//FIELD_TO_JSON(total_mined_from_captured), | ||
FIELD_TO_JSON(total_dropped), | ||
FIELD_TO_JSON(carried_at_end), | ||
{"mining_efficiency", mining_efficiency}, | ||
FIELD_TO_JSON(halite_per_dropoff), | ||
{"average_entity_distance", average_distance}}; | ||
|
@@ -74,7 +80,9 @@ void to_json(nlohmann::json &json, const PlayerStatistics &stats) { | |
*/ | ||
void to_json(nlohmann::json &json, const GameStatistics &stats) { | ||
json = {FIELD_TO_JSON(number_turns), | ||
FIELD_TO_JSON(player_statistics)}; | ||
FIELD_TO_JSON(player_statistics), | ||
FIELD_TO_JSON(execution_time), | ||
FIELD_TO_JSON(map_total_halite)}; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ constexpr auto SEPARATOR = '/'; | |
constexpr auto JSON_INDENT_LEVEL = 4; | ||
|
||
int main(int argc, char *argv[]) { | ||
auto engine_start = std::chrono::system_clock::now(); | ||
auto &constants = hlt::Constants::get_mut(); | ||
|
||
using namespace TCLAP; | ||
|
@@ -149,6 +150,12 @@ int main(int argc, char *argv[]) { | |
hlt::Replay replay{game_statistics, map_parameters.num_players, map_parameters.seed, map}; | ||
Logging::log("Map seed is " + std::to_string(map_parameters.seed)); | ||
|
||
for (const auto &row : map.grid) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Mixed tabs and spaces here too.) |
||
for (const auto &cell : row) { | ||
game_statistics.map_total_halite += cell.energy; | ||
} | ||
} | ||
|
||
hlt::Halite game(map, networking_config, game_statistics, replay); | ||
game.run_game(bot_commands, snapshot); | ||
|
||
|
@@ -175,6 +182,8 @@ int main(int argc, char *argv[]) { | |
static constexpr size_t MAX_DATE_STRING_LENGTH = 25; | ||
char time_string[MAX_DATE_STRING_LENGTH]; | ||
std::strftime(time_string, MAX_DATE_STRING_LENGTH, "%Y%m%d-%H%M%S%z", localtime); | ||
|
||
game_statistics.execution_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - engine_start).count(); | ||
|
||
if (!no_replay_switch.getValue()) { | ||
// Output gamefile. First try the replays folder; if that fails, just use the straight filename. | ||
|
@@ -245,9 +254,11 @@ int main(int argc, char *argv[]) { | |
results["terminated"][to_string(player_id)] = player.terminated; | ||
} | ||
} | ||
|
||
|
||
results["execution_time"] = game_statistics.execution_time; | ||
results["map_width"] = map_width; | ||
results["map_height"] = map_height; | ||
results["map_total_halite"] = game_statistics.map_total_halite; | ||
results["map_seed"] = seed; | ||
std::ostringstream stream; | ||
stream << type; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,14 @@ void SpawnEvent::to_json(nlohmann::json &json) const { | |
FIELD_TO_JSON(energy)}; | ||
} | ||
|
||
void SpawnEvent::update_stats(const Store &store, const Map &map, | ||
GameStatistics &stats) { | ||
(void)map; | ||
|
||
stats.player_statistics.at(owner_id.value).ships_spawned++; | ||
stats.player_statistics.at(owner_id.value).last_turn_ship_spawn = stats.turn_number; | ||
} | ||
|
||
/** | ||
* Convert capture event to json format | ||
* @param[out] json JSON to be filled by spawn event | ||
|
@@ -60,8 +68,15 @@ void CollisionEvent::update_stats(const Store &store, const Map &map, | |
ordered_id_map<Player, int> ships_involved; | ||
for (const auto &ship_id : ships) { | ||
const auto &entity = store.get_entity(ship_id); | ||
stats.player_statistics.at(entity.owner.value).all_collisions++; | ||
auto &player_stats = stats.player_statistics.at(entity.owner.value); | ||
|
||
ships_involved[entity.owner]++; | ||
player_stats.all_collisions++; | ||
player_stats.total_dropped += entity.energy; | ||
|
||
if (map.at(location).owner == entity.owner) { // There is a friendly dropoff | ||
player_stats.dropoff_collisions++; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should |
||
} | ||
for (const auto &[player_id, num_ships] : ships_involved) { | ||
// Increment self-collision to account for uncounted ship | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Watch out for mixed spaces/tabs here.)