Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Play bipedal walker
import numpy as np
from tinynet import RNN1L
import gym
pre_trained_weights = np.array(
[[-6.42131474e-02, 1.18558117e+00, -8.65697398e-02,
-7.25508614e-01, -1.64208890e+00, 2.36031412e-01,
-2.30686547e-01, 1.01184284e-02, 9.14193609e-02,
4.09360317e-01, 5.28414810e-01, 3.01208252e+00,
-9.78603700e-02, 3.53038690e-02, 8.94094020e-01,
2.90466615e-01, -1.79276182e-01, -2.17272103e-02,
-2.13970051e-01, -1.67635995e+00, -6.02311909e-02,
-1.96442401e+00, 1.19746455e-01, 1.79969903e-01,
1.05914865e+00, -6.51820003e-01, 1.37623963e-01,
-2.71994849e-01, 6.59062949e-01],
[ 2.02307561e+00, 1.20449209e+00, 6.05621780e-01,
6.98229811e-01, 2.14649694e+00, -5.37398203e-01,
-3.97149533e+00, -2.12493526e-01, -4.23998290e-02,
9.53130511e-01, 4.16741016e-01, -1.54060458e+00,
5.21017760e-01, -2.45511887e-01, 4.14342494e-01,
9.14911539e-01, -1.23614789e+00, 7.33691074e-01,
5.45596174e-01, -4.17843212e-02, -8.70911009e-02,
9.51670845e-01, 3.85517330e-02, 8.25852210e-03,
-1.90154830e+00, -8.03895467e-01, -4.54610968e-01,
5.96982247e-02, -4.74628318e-01],
[ 1.37118663e+00, 1.27937587e+00, -1.71887878e+00,
-1.94443529e+00, 8.90548993e-01, -7.23938737e-01,
1.79740914e-01, -5.48218269e-04, 6.50140805e-02,
-1.47901011e+00, -7.39203613e-01, -4.17242880e-01,
-4.00900026e-01, 2.04101041e-01, 5.31842291e-01,
-1.53630768e+00, 3.99904773e-01, -7.84735830e-01,
-1.62958331e+00, -5.39509441e-01, 1.39857350e+00,
-7.35478300e-01, 3.25341560e+00, 4.71190751e-01,
-5.17805666e-03, -1.22670637e+00, -2.69994440e-01,
-5.59723682e-01, 3.75500268e-01],
[ 3.47982673e-01, 5.91370880e-01, 2.42805457e+00,
8.28226086e-01, -1.08526012e+00, 1.99388318e-01,
-3.05907307e-01, 4.35067255e-02, -2.76692831e-02,
1.59416946e-01, -2.39363737e-01, -1.70776626e+00,
-2.36775784e-01, -4.18781827e-02, -9.31394093e-01,
-7.61417665e-01, -2.36382980e-01, -1.27730737e-01,
-5.48062621e-01, 5.19030962e-01, -3.08506491e-01,
-3.01197781e-01, -8.71729552e-02, 2.38021638e-01,
2.54997762e-01, -4.54133943e-01, -3.76671113e-02,
-9.02776638e-02, 3.64898985e-02]])
# Environment setup
env = gym.make("BipedalWalker-v2")
# env = gym.wrappers.Monitor(env, 'video', force = True) # Uncomment to save video
nactions = env.action_space.shape[0]
ninputs = env.reset().size
# Network setup
net = RNN1L(ninputs, nactions)
net.set_weights(pre_trained_weights)
# Gameplay loop
obs = env.reset()
score = 0
done = False
while not done:
env.render()
action = net.activate(obs)
obs, rew, done, info = env.step(action)
score += rew
print(f"Fitness: {score}")
env.close()
# import IPython; IPython.embed() # Uncomment to drop into iPython for analysis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.