Example #1
0
def run(arg):
    start_time = time.time()

    game_number = int(arg[1])

    #    PLAY_TYPE = 'step'
    #  PLAY_TYPE = 'batch'
    #  PLAY_TYPE = 'play'

    # Run the local debugger
    engine = LocalEngine(game=None)

    if game_number > 0:
        qbot = QLearnBot(engine.GetWorld(), load_file='saved_bots/qbot.json')
    else:
        # init qbot with weights 0
        qbot = QLearnBot(engine.GetWorld(), load_file=None)
        qbot.set_features(
            CompositingFeatures(AdvancedFeatures(), AdvancedFeatures()))
        qbot.set_weights([0 for j in range(0, qbot.features.num_features())])

    # Generate and play on random 30 x 30 map
    random_map = SymmetricMap(min_dim=50, max_dim=50)
    random_map.random_walk_map()
    fp = file("src/maps/2player/my_random.map", "w")
    fp.write(random_map.map_text())
    fp.close()

    # set up a game between current qbot and GreedyBot
    engine.AddBot(qbot)
    engine.AddBot(GreedyBot(engine.GetWorld()))
    qbot.ngames = game_number + 1

    engine.Run(PLAY_TYPE,
               arg + ["--run", "-m", "src/maps/2player/my_random.map"])
    qbot.save('saved_bots/qbot.json')
    # this is an easy way to look at the weights
    #qbot.save_readable('saved_bots/qbot-game-%d.txt' % game_number)

    end_time = time.time()
    print 'training done, delta time = ', end_time - start_time
Example #2
0
def run(arg):
    start_time = time.time()
    
    game_number = int(arg[1])
    
    #    PLAY_TYPE = 'step'
    #  PLAY_TYPE = 'batch'
    #  PLAY_TYPE = 'play'
    
    # Run the local debugger
    engine = LocalEngine(game=None)
    
    if game_number > 0:
        qbot = QLearnBot(engine.GetWorld(), load_file='saved_bots/qbot.json')
    else:
        # init qbot with weights 0
        qbot = QLearnBot(engine.GetWorld(), load_file=None)
        qbot.set_features(CompositingFeatures(AdvancedFeatures(), AdvancedFeatures()))
        qbot.set_weights([0 for j in range (0, qbot.features.num_features())])
        
    # Generate and play on random 30 x 30 map
    random_map = SymmetricMap(min_dim=50, max_dim=50)
    random_map.random_walk_map()
    fp = file("src/maps/2player/my_random.map", "w")
    fp.write(random_map.map_text())
    fp.close()
        
    # set up a game between current qbot and GreedyBot
    engine.AddBot(qbot)        
    engine.AddBot(GreedyBot(engine.GetWorld()))
    qbot.ngames = game_number + 1
    
    engine.Run(PLAY_TYPE, arg + ["--run", "-m", "src/maps/2player/my_random.map"])
    qbot.save('saved_bots/qbot.json')
    # this is an easy way to look at the weights
    #qbot.save_readable('saved_bots/qbot-game-%d.txt' % game_number)
        
    end_time = time.time()
    print 'training done, delta time = ', end_time-start_time
Example #3
0
    # Run the local debugger
    engine = LocalEngine(game=None)

    if game_number > 0:
        qbot = QLearnBot(engine.GetWorld(), load_file='saved_bots/qbot.json')
    else:
        # init qbot with weights 0
        qbot = QLearnBot(engine.GetWorld(), load_file=None)
        qbot.set_features(CompositingFeatures(BasicFeatures(),
                                              BasicFeatures()))
        qbot.set_weights([0 for j in range(0, qbot.features.num_features())])

    # Generate and play on random 30 x 30 map
    random_map = SymmetricMap(min_dim=50, max_dim=50)
    random_map.random_walk_map()
    fp = file("src/maps/2player/my_random.map", "w")
    fp.write(random_map.map_text())
    fp.close()

    # set up a game between current qbot and GreedyBot
    engine.AddBot(qbot)
    engine.AddBot(GreedyBot(engine.GetWorld()))
    qbot.ngames = game_number + 1
    engine.Run(PLAY_TYPE,
               sys.argv + ["--run", "-m", "src/maps/2player/my_random.map"])
    qbot.save('saved_bots/qbot.json')
    # this is an easy way to look at the weights
    qbot.save_readable('saved_bots/qbot-game-%d.txt' % game_number)

    end_time = time.time()
Example #4
0
    if game_number > 0: 
        qbot1 = QLearnBot(engine.GetWorld(), load_file='saved_bots/qbot1.json')
        qbot2 = QLearnBot(engine.GetWorld(), load_file='saved_bots/qbot2.json')
    else:
        # init qbot with weights 0
        qbot1 = QLearnBot(engine.GetWorld(), load_file=None)
        qbot1.set_features(CompositingFeatures(BasicFeatures(), QualifyingFeatures()))
        qbot1.set_weights([0 for j in range (0, qbot1.features.num_features())])
        qbot2 = QLearnBot(engine.GetWorld(), load_file=None)
        qbot2.set_features(CompositingFeatures(BasicFeatures(), QualifyingFeatures()))
        qbot2.set_weights([0 for j in range (0, qbot2.features.num_features())])
      
  # Generate and play on random 30 x 30 map
    random_map = SymmetricMap(min_dim=30, max_dim=30)
    random_map.random_walk_map()
    fp = file("src/maps/2player/my_random.map", "w")
    fp.write(random_map.map_text())
    fp.close()
    qbot1.ngames = game_number + 1
    qbot2.ngames = game_number + 1
    
    if game_number % 5 == 4:
        engine.AddBot(GreedyBot(engine.GetWorld()))        
        engine.AddBot(qbot1)
        engine.Run(sys.argv + ["--run", "-m", "src/maps/2player/my_random.map", "-t", str(MAX_TURNS)], run_mode=PLAY_TYPE)
        engine = LocalEngine(game=None, run_mode=PLAY_TYPE)
        engine.AddBot(GreedyBot(engine.GetWorld()))        
        engine.AddBot(qbot2)
        engine.Run(sys.argv + ["--run", "-m", "src/maps/2player/my_random.map", "-t", str(MAX_TURNS)], run_mode=PLAY_TYPE)
        print 'done test vs greedybot'