File size: 1,325 Bytes
079c32c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from collections import namedtuple

import numpy as np

from ding.envs.common import EnvElement


class GfootballReward(EnvElement):
    _name = "gfootballReward"
    _reward_keys = ['reward_value']
    Reward = namedtuple('Action', _reward_keys)

    MinReward = -1.0
    MaxReward = 1.0

    def _init(self, cfg) -> None:
        self._default_val = 0.0
        self.template = {
            'reward_value': {
                'name': 'reward_value',
                'shape': (1, ),
                'value': {
                    'min': -1.0,
                    'max': 1.0,
                    'dtype': float,
                    'dinfo': 'float value',
                },
                'env_value': 'reward of action',
                'to_agent_processor': lambda x: x,
                'from_agent_processor': lambda x: x,
                'necessary': True,
            }
        }
        self._shape = (1, )
        self._value = {
            'min': -1.0,
            'max': 1.0,
            'dtype': float,
            'dinfo': 'float value',
        }

    def _to_agent_processor(self, reward: float) -> np.array:
        return np.array([reward], dtype=float)

    def _from_agent_processor(self, reward: float) -> float:
        return reward

    def _details(self):
        return '\t'.join(self._reward_keys)