input: Write a function to develop a reinforcement learning environment for playing tic-tac-toe in Python. Implement a `TicTacToeEnv` class with an initializer, a reset method, a step function, and a method to check for a winner. The class should manage the state of the game, switch players, and return the state, reward, done flag, and additional info after each step. The step function should provide a reward of 1 for a win, 0 for ongoing games, and 0.5 for a draw. If the player completes a valid move, the function should switch the current player to the opponent. Write assertions to validate the environment's functionality. The function should output a game loop that plays a full tic-tac-toe game using random actions.
  
  assert env.step(0) == (['X', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 0, False, None)
  assert env.step(1) == (['X', 'O', ' ', ' ', ' ', ' ', ' ', ' ', ' '], 0, False, None)
  assert env.step(4) == (['X', 'O', ' ', ' ', 'X', ' ', ' ', ' ', ' '], 0, False, None)
  assert env.step(8) == (['X', 'O', ' ', ' ', 'X', ' ', ' ', ' ', 'O'], 0, False, None)
  assert env.check_winner() == None
  assert env.step(2) == (['X', 'O', 'X', ' ', 'X', ' ', ' ', ' ', 'O'], 1, True, None)
output: 
  class TicTacToeEnv:
      def __init__(self):
          self.board = [' '] * 9
          self.current_player = 'X'
          self.winner = None
  
      def reset(self):
          self.board = [' '] * 9
          self.current_player = 'X'
          self.winner = None
          return self.board
  
      def step(self, action):
          if self.board[action] != ' ':
              return self.board, 0, False, None
          
          self.board[action] = self.current_player
          winner = self.check_winner()
          
          if winner:
              self.winner = winner
              return self.board, 1, True, None
          
          if ' ' not in self.board:
              return self.board, 0.5, True, None
          
          self.current_player = 'O' if self.current_player == 'X' else 'X'
          return self.board, 0, False, None
  
      def check_winner(self):
          lines = [
              [0, 1, 2], [3, 4, 5], [6, 7, 8],  # rows
              [0, 3, 6], [1, 4, 7], [2, 5, 8],  # columns
              [0, 4, 8], [2, 4, 6]              # diagonals
          ]
          for line in lines:
              if self.board[line[0]] == self.board[line[1]] == self.board[line[2]] != ' ':
                  return self.board[line[0]]
          return None
  