Beispiel #1
0
 def test_parse_valid_actions_singles(self):
     actions = parser.parse_valid_actions(single())
     all_actions = parser.all_actions_singles()
     self.assertEqual(len(all_actions), len(actions))
     for expected, actual in zip(all_actions, actions):
         if is_normal_move(expected):
             self.assertIsNot(actual, None)
         else:
             self.assertIs(actual, None)
Beispiel #2
0
 def test_parse_valid_actions_mega(self):
     actions = parser.parse_valid_actions(single_with_mega())
     all_actions = parser.all_actions_singles()
     self.assertEqual(len(all_actions), len(actions))
     for expected, actual in zip(all_actions, actions):
         if is_normal_move(expected) or is_mega_move(expected) or is_switch(
                 expected, exclude=[1, 5]):
             self.assertIsNot(actual, None)
         else:
             self.assertIs(actual, None)
Beispiel #3
0
    def extract(self, state, candidates):
        rv = extract(state, self.poke_features)
        candidates = list(candidates)

        while len(candidates) < len(parser.all_actions_singles()):
            candidates.append(None)

        rv['mask'] = np.asarray([float(bool(c))
                                 for c in candidates]).astype(config.nt())

        return rv
Beispiel #4
0
    def _action_extra(self, n):
        actions = parser.all_actions_singles()
        mega_mask = ag.Variable(
            torch.ByteTensor([a.endswith(' mega') for a in actions
                              ]).type(config.tt()).unsqueeze(0).unsqueeze(-1))

        zmove_mask = ag.Variable(
            torch.ByteTensor([a.endswith(' zmove') for a in actions
                              ]).type(config.tt()).unsqueeze(0).unsqueeze(-1))

        ultra_mask = ag.Variable(
            torch.ByteTensor([a.endswith(' ultra') for a in actions
                              ]).type(config.tt()).unsqueeze(0).unsqueeze(-1))

        return (self.policy_mega(mega_mask.expand(n, -1, -1)) +
                self.policy_zmove(zmove_mask.expand(n, -1, -1)) +
                self.policy_ultra(ultra_mask.expand(n, -1, -1)))
Beispiel #5
0
                    result = result.get()
                probs = result['probs']
                probs = (1. - self._epsilon) * probs + (
                    self._epsilon * mask / sum(mask)).astype(config.nt())
                if self._play_best_move:
                    action = np.argmax(probs)
                else:
                    action = np.random.choice(len(self.candidates), p=probs)

                # TODO: why not just use self.candidates?
                if self.request.get('teamPreview'):
                    all_actions = _teampreview_actions
                else:
                    all_actions = _singles_actions

                action_string = all_actions[action]
                result['candidates'] = self.candidates
                result['state'] = state
                result['action'] = action
                result['actionString'] = action_string
                result['_updates'] = block_updates
            self.blocks.append(result)
            rv.set(action_string)

        gevent.spawn(fn)
        return rv


_engine = Engine()
_singles_actions = parser.all_actions_singles()
_teampreview_actions = parser.team_preview_actions_singles()