<jupyter_start><jupyter_text>Q learning with Tic Tac Toe[Assignment description](RL.pdf)  Imports<jupyter_code>import gym
import gym_tic_tac_toe<jupyter_output><empty_output><jupyter_text>Testing the game<jupyter_code>def play_game(moves):
    env = gym.make('tic_tac_toe-v1')
    env.reset()
    
    for move in moves:
        # get all possible moves
        print(env.move_generator())

        # returns: resulting_state, reward, finished, _ = env.step(action)
        print(env.step(move))
        
        # draws a board
        env.render()
        
    return env
# every move is a list of two elements: 
#   * player number (1 for crosses, -1 for naughts)
#   * tile number – one of:
#        0 1 2
#        3 4 5
#        7 8 9

moves = [[1,0], [-1,1], [1,2], [-1, 3], [1, 4], [-1, 5], [1, 7], [-1, 6], [1, 8]]
_ = play_game(moves)<jupyter_output>[[1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8]]
({'board': [1, 0, 0, 0, 0, 0, 0, 0, 0], 'on_move': -1}, 0, False, {})
on move:  O
X     
      
      
[[-1, 1], [-1, 2], [-1, 3], [-1, 4], [-1, 5], [-1, 6], [-1, 7], [-1, 8]]
({'board': [1, -1, 0, 0, 0, 0, 0, 0, 0], 'on_move': 1}, 0, False, {})
on move:  X
X O   
      
      
[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8]]
({'board': [1, -1, 1, 0, 0, 0, 0, 0, 0], 'on_move': -1}, 0, False, {})
on move:  O
X O X 
      
      
[[-1, 3], [-1, 4], [-1, 5], [-1, 6], [-1, 7], [-1, 8]]
({'board': [1, -1, 1, -1, 0, 0, 0, 0, 0], 'on_move': 1}, 0, False, {})
on move:  X
X O X 
O     
      
[[1, 4], [1, 5], [1, 6], [1, 7], [1, 8]]
({'board': [1, -1, 1, -1, 1, 0, 0, 0, 0], 'on_move': -1}, 0, False, {})
on move:  O
X O X 
O X   
      
[[-1, 5], [-1, 6], [-1, 7], [-1, 8]]
({'board': [1, -1, 1, -1, 1, -1, 0, 0, 0], 'on_move': 1}, 0, False, {})
on move:  X
X O X 
O X O 
      
[[1, 6], [1, 7], [1, 8]]
({'board': [1, [...]
{'fraction_non_alphanumeric': 0.26716738197424894, 'fraction_numerical': 0.0971030042918455, 'mean_word_length': 2.2776801405975395, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '607952', 'license': 'MIT', 'n_tokens_mistral': 978, 'n_tokens_neox': 873, 'n_words': 293, 'path': 'Explore.ipynb', 'repo_name': 'PaulinaSzy/gym-tic-tac-toe', 'size': '1864'}