from .._BlackJack import BlackJackCPP

import gym
import ctypes
import numpy as np
from gym import spaces


class BlackJack(gym.Env):
    def __init__(self, natural=False):
        self.env = BlackJackCPP(natural)
        self.action_space = spaces.Discrete(2)
        self.observation_space = spaces.Tuple((
            spaces.Discrete(32),
            spaces.Discrete(11),
            spaces.Discrete(2)
        ))
        self.state = None
        self.natural = natural

    def seed(self, seed=None):
        if seed is None:
            return [self.env.get_seed()]
        else:
            if not isinstance(seed, ctypes.c_uint32):
                seed = ctypes.c_uint32(seed).value
            self.env.set_seed(seed)
            return [seed]

    def step(self, action):
        assert self.action_space.contains(action)
        state, reward, done = self.env.step(action)
        self.state = np.array(state)
        return self.state, reward, done, {}

    def render(self, mode='human'):
        return None

    def reset(self):
        self.state = np.array(self.env.reset())
        return self.state

[((242, 260), 'gym.spaces.Discrete', 'spaces.Discrete', (['(2)'], {}), '(2)\n', (257, 260), False, 'from gym import spaces\n'), ((905, 920), 'numpy.array', 'np.array', (['state'], {}), '(state)\n', (913, 920), True, 'import numpy as np\n'), ((321, 340), 'gym.spaces.Discrete', 'spaces.Discrete', (['(32)'], {}), '(32)\n', (336, 340), False, 'from gym import spaces\n'), ((354, 373), 'gym.spaces.Discrete', 'spaces.Discrete', (['(11)'], {}), '(11)\n', (369, 373), False, 'from gym import spaces\n'), ((387, 405), 'gym.spaces.Discrete', 'spaces.Discrete', (['(2)'], {}), '(2)\n', (402, 405), False, 'from gym import spaces\n'), ((663, 684), 'ctypes.c_uint32', 'ctypes.c_uint32', (['seed'], {}), '(seed)\n', (678, 684), False, 'import ctypes\n')]