File size: 2,608 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from collections import namedtuple

import numpy as np

from ding.envs.common import EnvElement


class GfootballSpAction(EnvElement):
    _name = "gfootballSpAction"
    _action_keys = ['action_type']
    Action = namedtuple('Action', _action_keys)

    def _init(self, cfg):
        self.default_val = None
        self.template = {
            'action_type': {
                'name': 'action_type',
                'shape': (17, ),
                'value': {
                    'min': 0,
                    'max': 16,
                    'dtype': int,
                    'dinfo': 'int value',
                },
                'env_value': 'type of action, refer to AtariEnv._action_set',
                'to_agent_processor': lambda x: x,
                'from_agent_processor': lambda x: x,
                'necessary': True,
            }
        }
        self._shape = (17, )
        self._value = {
            'min': 0,
            'max': 16,
            'dtype': int,
            'dinfo': 'int value, action_meanings: []',
        }

    def _to_agent_processor(self, action):
        return action

    def _from_agent_processor(self, action):
        return action

    # override
    def _details(self):
        return '\t'.join(self._action_keys)


class GfootballRawAction(EnvElement):
    '''
    For raw action set please reference
    <https://github.com/google-research/football/blob/master/gfootball/doc/observation.md#default-action-set>.
    '''
    _name = "gfootballRawAction"
    _action_keys = ['action_type']
    Action = namedtuple('Action', _action_keys)

    def _init(self, cfg):
        self._default_val = None
        self.template = {
            'action_type': {
                'name': 'action_type',
                'shape': (19, ),
                'value': {
                    'min': 0,
                    'max': 18,
                    'dtype': int,
                    'dinfo': 'int value',
                },
                'env_value': 'type of action, refer to AtariEnv._action_set',
                'to_agent_processor': lambda x: x,
                'from_agent_processor': lambda x: x,
                'necessary': True,
            }
        }
        self._shape = (19, )
        self._value = {
            'min': 0,
            'max': 18,
            'dtype': int,
            'dinfo': 'int value, action_meanings: []',
        }

    def _to_agent_processor(self, action):
        return action

    def _from_agent_processor(self, action):
        return action

    # override
    def _details(self):
        return '\t'.join(self._action_keys)