Mode without visualization
@@ -10,6 +10,8 @@ from torch.autograd import Variable
from lib import wrappers
from lib import dqn_model
+import collections
+
DEFAULT_ENV_NAME = "PongNoFrameskip-v4"
FPS = 25
@@ -20,6 +22,8 @@ if __name__ == "__main__":
parser.add_argument("-e", "--env", default=DEFAULT_ENV_NAME,
help="Environment name to use, default=" + DEFAULT_ENV_NAME)
parser.add_argument("-r", "--record", help="Directory to store video recording")
+ parser.add_argument("--no-visualize", default=True, action='store_false', dest='visualize',
+ help="Disable visualization of the game play")
args = parser.parse_args()
env = wrappers.make_env(args.env)
@@ -30,19 +34,24 @@ if __name__ == "__main__":
state = env.reset()
total_reward = 0.0
+ c = collections.Counter()
+
while True:
start_ts = time.time()
+ if args.visualize:
env.render()
state_v = Variable(torch.from_numpy(np.array([state], copy=False)), volatile=False)
q_vals = net(state_v).data.numpy()[0]
action = np.argmax(q_vals)
+ c[action] += 1
state, reward, done, _ = env.step(action)
total_reward += reward
if done:
break
+ if args.visualize:
delta = 1/FPS - (time.time() - start_ts)
if delta > 0:
time.sleep(delta)
print("Total reward: %.2f" % total_reward)
-
+ print("Action counts:", c)
