import random import numpy import sys import time import os import json from pong_environment_play import PongGame policy_filename = "pong_policy.dat" values_filename = "pong_values.dat" alpha = 0.1 # values / critic learning parameter beta = 0.1 # actor learning parameter gamma = 0.9 # error signal: future states parameter env = PongGame(["human", "computer"], bins=12) world_dim = env.getWorldDim() num_possible_moves = env.getActionDim() state = env.getState(1) pol_file = None val_file = None if os.path.exists(policy_filename): pol_file = open(policy_filename, "r+") policy = numpy.array(json.loads(pol_file.read())) pol_file.close() else: # create random policy
import random from pong_environment_play import PongGame import time env = PongGame(["human", "computer"]) env.start() while True: time.sleep(0.05) direction = random.randint(-1, 1) outcome = 0 state, outcome = env.move(direction, 1)
# Add place cell to list if DEBUG: print("\tPlace cell mu:%f" % cell_mu) cells.append(PlaceCell(cell_mu, cell_sigma, cell_min_rate, cell_max_rate, population_size, population_label_stem + ("_%u" % c), sdp_connection)) return cells # ------------------------------------------ # PyNN entry point # ------------------------------------------ # SpiNNaker setup sim.setup(timestep=1.0,min_delay=1.0,max_delay=10.0) # Create human vs ai pong game and start it pong_game = PongGame(["human", "computer"]) pong_game.start() # Create spinnaker pong player player_thread = SpiNNakerPlayer(BOARD_ADDRESS, 0, pong_game, MAX_Y, UPDATE_TIMESTEP, NUM_PADDLE_CELLS, PADDLE_CELL_SIGMA, CELL_MIN_RATE, PADDLE_CELL_MAX_RATE, PADDLE_CELL_POP_SIZE, NUM_BALL_CELLS, BALL_CELL_SIGMA, CELL_MIN_RATE, BALL_CELL_MAX_RATE, BALL_CELL_POP_SIZE) # Start player thread and simulation player_thread.start() sim.run(SIM_TIME)