<jupyter_start><jupyter_text>Normal Game Play<jupyter_code>env = h_env.HockeyEnv()<jupyter_output><empty_output><jupyter_text>have a look at the initialization condition: alternating who starts and are random in puck position<jupyter_code>obs = env.reset()
obs_agent2 = env.obs_agent_two()
_ = env.render()<jupyter_output><empty_output><jupyter_text>one episode with random agents<jupyter_code>obs = env.reset()
obs_agent2 = env.obs_agent_two()

for _ in range(600):
    env.render()
    a1 = np.random.uniform(-1,1,4)
    a2 = np.random.uniform(-1,1,4)    
    obs, r, d, info = env.step(np.hstack([a1,a2]))    
    obs_agent2 = env.obs_agent_two()
    if d: break<jupyter_output><empty_output><jupyter_text>Without rendering, it runs much faster "info" dict contains useful proxy rewards and winning information<jupyter_code>info<jupyter_output><empty_output><jupyter_text>Winner == 0: drawWinner == 1: you (left player)Winner == -1: opponent wins (right player)<jupyter_code>env.close()<jupyter_output><empty_output><jupyter_text>Train Shooting<jupyter_code>env = h_env.HockeyEnv(mode=h_env.HockeyEnv.TRAIN_SHOOTING)
o = env.reset()
_ = env.render()

for _ in range(50):
    env.render()
    a1 = [1,0,0,1] # np.random.uniform(-1,1,4)
    a2 = [0,0.,0,0] 
    obs, r, d, info = env.step(np.hstack([a1,a2]))    
    obs_agent2 = env.obs_agent_two()
    if d: break
env.close()<jupyter_output><empty_output><jupyter_text>Train DEFENDING<jupyter_code>env = h_env.HockeyEnv(mode=h_env.HockeyEnv.TRAIN_DEFENSE)
o = env.reset()
_ = env.render()

for _ in range(60):
    env.render()
    a1 = [0.1,0,0,1] # np.random.uniform(-1,1,3)
    a2 = [0,0.,0,0] 
    obs, r, d, info = env.step(np.hstack([a1,a2]))
    print(r)
    obs_agent2 = env.obs_agent_two()
    if d: break
env.close()<jupyter_output><empty_output><jupyter_text>Using discrete actions<jupyter_code>import random
env = h_env.HockeyEnv(mode=h_env.HockeyEnv.TRAIN_SHOOTING)
env.reset()
for _ in range(200):
    env.render()
    a1_discrete = random.randint(0,7)
    a1 = env.discrete_to_continous_action(a1_discrete)
    a2 = [0,0.,0,0 ] 
    obs, r, d, info = env.step(np.hstack([a1,a2]))    
    obs_agent2 = env.obs_agent_two()
    if d: break
env.close()<jupyter_output><empty_output><jupyter_text>Hand-crafted Opponent<jupyter_code>env = h_env.HockeyEnv()
o = env.reset()
_ = env.render()
player1 = h_env.BasicOpponent(weak=False)
player2 = h_env.BasicOpponent()
obs_buffer = []
reward_buffer=[]
obs = env.reset()
obs_agent2 = env.obs_agent_two()
for _ in range(250):
    env.render()
    a1 = player1.act(obs)
    a2 = player2.act(obs_agent2)
    obs, r, d, info = env.step(np.hstack([a1,a2]))    
    obs_buffer.append(obs)
    reward_buffer.append(r)
    obs_agent2 = env.obs_agent_two()
    if d: break
obs_buffer = np.asarray(obs_buffer)
reward_buffer = np.asarray(reward_buffer)
np.mean(obs_buffer,axis=0)
np.std(obs_buffer,axis=0)<jupyter_output><empty_output><jupyter_text>If you want to use a fixed observation scaling, this might be a reasonable choice<jupyter_code>scaling = [ 1.0,  1.0 , 0.5, 4.0, 4.0, 4.0,  
            1.0,  1.0,  0.5, 4.0, 4.0, 4.0,  
            2.0, 2.0, 10.0, 10.0, 4,0 ,4,0]
import pylab as plt
plt.plot(obs_buffer[:,2])
plt.plot(obs_buffer[:,8])
plt.plot(obs_buffer[:,12])
plt.plot(reward_buffer[:])
np.sum(reward_buffer)
env.close()<jupyter_output><empty_output><jupyter_text>Human Opponent<jupyter_code>env = h_env.HockeyEnv()
player1 = h_env.HumanOpponent(env=env, player=1)
player2 = h_env.BasicOpponent()

player1 = h_env.BasicOpponent()
player2 = h_env.HumanOpponent(env=env, player=2)

obs = env.reset()

env.render()
time.sleep(1)
obs_agent2 = env.obs_agent_two()
for _ in range(20):
    time.sleep(0.2)
    env.render()
    a1 = player1.act(obs) 
    a2 = player2.act(obs_agent2)
    obs, r, d, info = env.step(np.hstack([a1,a2]))    
    obs_agent2 = env.obs_agent_two()
    if d: break
env.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15236160487557135, 'fraction_numerical': 0.03809040121889284, 'mean_word_length': 4.6676258992805755, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '381947', 'license': 'MIT', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1646, 'n_words': 272, 'path': 'Hockey-Env.ipynb', 'repo_name': 'antic11d/laser-hockey-env', 'size': '3938'}