From 2bbc202f8fa5740742ba66f237a43cce6b752aff Mon Sep 17 00:00:00 2001 From: ComputerTech312 Date: Sat, 13 Sep 2025 15:07:32 +0100 Subject: [PATCH] Fix KeyError: 'fastest_shot' by ensuring complete channel records initialization - Fixed incomplete channel_records initialization in shoot command - Fixed incomplete channel_records initialization in wild shot tracking - All channel records now properly include: fastest_shot, last_duck, total_ducks, total_shots - Resolves runtime error when update_channel_records tries to access fastest_shot field --- duckhunt/simple_duckhunt.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/duckhunt/simple_duckhunt.py b/duckhunt/simple_duckhunt.py index 3e06b59..e3852ba 100644 --- a/duckhunt/simple_duckhunt.py +++ b/duckhunt/simple_duckhunt.py @@ -899,7 +899,12 @@ class SimpleIRCBot: # Track total shots for channel statistics if channel not in self.channel_records: - self.channel_records[channel] = {'total_shots': 0, 'total_ducks': 0} + self.channel_records[channel] = { + 'fastest_shot': None, + 'last_duck': None, + 'total_ducks': 0, + 'total_shots': 0 + } self.channel_records[channel]['total_shots'] += 1 # Check for hit @@ -1004,7 +1009,12 @@ class SimpleIRCBot: # Track wild shots in channel statistics if channel not in self.channel_records: - self.channel_records[channel] = {'total_shots': 0, 'total_ducks': 0} + self.channel_records[channel] = { + 'fastest_shot': None, + 'last_duck': None, + 'total_ducks': 0, + 'total_shots': 0 + } self.channel_records[channel]['total_shots'] += 1 # Calculate penalties based on level