File size: 1,051 Bytes
ac5cfba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.

"""Event reward component for Pokemon Red."""

from typing import Any, Dict

from .base import BaseRewardComponent


class EventReward(BaseRewardComponent):
    """
    Rewards triggering in-game event flags.
    
    Pokemon Red uses event flags to track story progression,
    item collection, NPC interactions, etc. This component
    rewards activating new event flags.
    
    Attributes:
        weight: Reward per event triggered (default 0.1).
    """
    
    def __init__(self, weight: float = 0.1, enabled: bool = True):
        super().__init__(name="event", weight=weight, enabled=enabled)
    
    def calculate(
        self, state: Dict[str, Any], prev_state: Dict[str, Any]
    ) -> float:
        """Calculate reward for new events triggered."""
        current_events = state.get("event_count", 0)
        previous_events = prev_state.get("event_count", 0)
        new_events = current_events - previous_events
        return max(0.0, float(new_events))