continueRunRun = 0; newRun = False; currentRun = 1; reRun = True; reRunGen = 289; reRunRun = 1; def getFitness(inputs): return (1 if inputs['digit'] == inputs['best_digit'] else 0); def getRunning(inputs): return inputs['steps'] <= imageset_size; runConfig = RunnerConfig(getFitness,getRunning,parallel=False,gameName='image_classification', returnData=[IOData('image','ndarray',array_size=[784])],num_trials=1,num_generations=None); runConfig.logging = True; runConfig.logPath = f'logs\\image-classification\\run-{currentRun}-log.txt'; runConfig.playback_fps = 20; runConfig.fitness_collection_type='continuous' print(runConfig.gameName); runner = GameRunner(game,runConfig); if (continueRun): winner = runner.continue_run('run_' + str(continueRunRun)); print('\nBest genome:\n{!s}'.format(winner)); else: local_dir = os.path.dirname(__file__) config_path = os.path.join(local_dir, 'config-image-classification') config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction, neat.DefaultSpeciesSet, neat.DefaultStagnation,
return inputs['cleared_lines'] + (0.01 * inputs['line_density']) + ( 0.00001 * inputs['steps']) + (inputs['cleared_lines'] / (1 + inputs['steps']) * 20) def getRunning(inputs): return inputs['is_alive'] and (inputs['steps'] < steps_threshold) runConfig = TetrisRunnerConfig(getFitness, getRunning, parallel=False, returnData=[ 'piece_id', 'piece_x', 'piece_y', 'piece_rotation', IOData('contours', 'array', array_size=[10]) ], gameName='Tetris', num_trials=100, num_generations=None) runConfig.playback_fps = 20 runner = GameRunner(game, runConfig) if (continueRun): winner = runner.continue_run('run_' + str(continueRunRun)) print('\nBest genome:\n{!s}'.format(winner)) else: local_dir = os.path.dirname(__file__) config_path = os.path.join(local_dir, 'config-tetris-gamerunner') config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction, neat.DefaultSpeciesSet, neat.DefaultStagnation,
def getFitness(inputs): return (1 if inputs['digit'] == inputs['best_digit'] else 0) def getRunning(inputs): return inputs['steps'] <= imageset_size runConfig = RunnerConfig( getFitness, getRunning, parallel=False, gameName='image_classification', returnData=[IOData('image', 'ndarray', array_size=[784])], num_trials=1, num_generations=None) runConfig.logging = True runConfig.logPath = f'logs\\image-classification\\run-{currentRun}-log.txt' runConfig.playback_fps = 20 runConfig.fitness_collection_type = 'continuous' print(runConfig.gameName) runner = GameRunner(game, runConfig) if (continueRun): winner = runner.continue_run('run_' + str(continueRunRun)) print('\nBest genome:\n{!s}'.format(winner)) else: local_dir = os.path.dirname(__file__) config_path = os.path.join(local_dir, 'config-image-classification')
def getRunning(inputs): return (not (inputs['done']) and (not inputs['stillness_time'] > steps_threshold)) runConfig = NESGymRunnerConfig(getFitness, getRunning, parallel=False, gameName='gym_nes_smb1', returnData=[ 'stage', 'status', 'world', 'x_pos', 'y_pos', IOData('enemy_type', 'array', array_size=[5]), IOData('enemy_x', 'array', array_size=[5]), IOData('enemy_y', 'array', array_size=[5]), IOData('blocks', 'array', array_size=[8, 8]), 'powerup_x', 'powerup_y' ], num_trials=1, num_generations=None) runConfig.logging = True runConfig.logPath = 'logs\\smb1\\run-0-log.txt' runConfig.playback_fps = 20 runConfig.fitness_collection_type = 'continuous' print(runConfig.gameName)
def getRunning(inputs): return not inputs['dead'] and inputs['steps'] < max_length game_name = 'dinosaur_game' runConfig = RunnerConfig(getFitness, getRunning, parallel=False, gameName=game_name, returnData=[ 'yPos', 'speed', IOData('near_obstacles', 'array', array_size=[3, 4]) ], num_trials=20, num_generations=None) runConfig.logging = True runConfig.logPath = f'logs\\{game_name}\\run-{run}-log.txt' runConfig.playback_fps = 20 print(runConfig.gameName) runner = GameRunner(game, runConfig) if (continueRun): winner = runner.continue_run('run_' + str(run)) print('\nBest genome:\n{!s}'.format(winner)) else: local_dir = os.path.dirname(__file__)
currentRun = 9; reRun = False; reRunGen = 8; reRunRun = 1; steps_threshold = 600; smb1Env.setWindowName('SuperMarioBros-v0 run {0}'.format(continueRunRun if continueRun else (currentRun if newRun else reRunRun))); def getFitness(inputs): return inputs['gym-reward']; def getRunning(inputs): return (not(inputs['done']) and (not inputs['stillness_time'] > steps_threshold)); runConfig = NESGymRunnerConfig(getFitness,getRunning,parallel=False,gameName='gym_nes_smb1',returnData=['stage','status','world','x_pos','y_pos',IOData('enemy_type','array',array_size=[5]),IOData('enemy_x','array',array_size=[5]),IOData('enemy_y','array',array_size=[5]),IOData('blocks','array',array_size=[8,8]),IOData('enemies','array',array_size=(8,8)),'powerup_x','powerup_y'],num_trials=1,num_generations=None); runConfig.logging = True; runConfig.logPath = f'logs\\smb1\\run-{currentRun}-log.txt'; runConfig.playback_fps = 20; runConfig.fitness_collection_type='continuous' print(runConfig.gameName); runner = GameRunner(game,runConfig); if (continueRun): winner = runner.continue_run('run_' + str(continueRunRun)); print('\nBest genome:\n{!s}'.format(winner)); else: local_dir = os.path.dirname(__file__) config_path = os.path.join(local_dir, 'config-gym-nes-smb1') config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction, neat.DefaultSpeciesSet, neat.DefaultStagnation,
run = 4; reRunGen = 154; max_length = 10000; def getFitness(inputs): return inputs['steps'] def getRunning(inputs): return not inputs['dead'] and inputs['steps'] < max_length; game_name = 'dinosaur_game' runConfig = RunnerConfig(getFitness,getRunning,parallel=False,gameName=game_name, returnData=['yPos','speed',IOData('near_obstacles','array',array_size=[3,4])],num_trials=20,num_generations=None); runConfig.logging = True; runConfig.logPath = f'logs\\{game_name}\\run-{run}-log.txt'; runConfig.playback_fps = 120; print(runConfig.gameName); runner = GameRunner(game,runConfig); if (continueRun): winner = runner.continue_run('run_' + str(run)); print('\nBest genome:\n{!s}'.format(winner)); else: local_dir = os.path.dirname(__file__) config_path = os.path.join(local_dir, 'config-dinosaur-runner') config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction, neat.DefaultSpeciesSet, neat.DefaultStagnation, config_path)