-
Notifications
You must be signed in to change notification settings - Fork 125
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
Print game stats to console #472
Conversation
At the end of the game we would like to see details about the each driver's runs, like how many penguins were collected out of possible number of penguins, number of jumps and breaks that scored points, number of collisions with obstacles. These details are printed to the console.
@sleviim Please review:) |
Thanks for sharing the example. I don't think it is very clear as is, and the code to
Example output:
The advantage is keeping stats in an easy to use way inside the program, making the output machine readable so it is easy to consume by other programs, and having no code to maintain for formatting the results. |
self.penguin_collected = 0 | ||
self.water_collected = 0 | ||
self.crack_collected = 0 | ||
self.collision_count = 0 |
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.
self.penguin_collected = 0 | |
self.water_collected = 0 | |
self.crack_collected = 0 | |
self.collision_count = 0 | |
self.penguin_collected = None | |
self.water_collected = None | |
self.crack_collected = None | |
self.collision_count = None |
the convention is to init to None and then use reset to set to 0
self.crack_counter = 0 | ||
self.water_counter = 0 |
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.
cracks and waters are never counted, need to add counters or remove them
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.
better set to None, and set to zero in the reset method.
if obstacles.PENGUIN in self._matrix[0]: | ||
self.penguin_counter += 1 |
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.
better to count at the _generate_row
method
@@ -39,6 +49,7 @@ def clear(self, x, y): | |||
self._matrix[y][x] = obstacles.NONE | |||
|
|||
def reset(self): | |||
self.penguin_counter = 0 |
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.
need to reset all the other counters too
lines.append(line) | ||
log.info("%s", os.linesep.join(lines)) | ||
|
||
def loop(self): | ||
self.track.update() | ||
self.track.searching_penguin() |
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.
if we count obstacles in the generate method, we don't need this call
@@ -107,13 +107,24 @@ def drive_player(self, name, info): | |||
def print_stats(self): | |||
lines = ['Stats:'] | |||
top_scorers = sorted(six.itervalues(self.players), reverse=True) | |||
line = '%2s | %15s | %5s | %9s | %9s | %9s | %10s |' % \ |
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.
I agree with #472 (comment), a stats struct and yaml dump makes more sense to me too.
At the end of the game we would like to see details about the each driver's runs, like how many penguins were collected out of possible number of penguins, number of jumps and breaks that scored points, number of collisions with obstacles.
These details are printed to the console.
Example: