Пример #1
0
 def start_game(self, map_type):
     self.agents = [Player(self, 'green', pygame.K_d, pygame.K_s, pygame.K_a, pygame.K_w, pygame.K_f, pygame.K_g, 100, 100, 180),
                    Player(self, 'purple', pygame.K_RIGHT, pygame.K_DOWN, pygame.K_LEFT, pygame.K_UP, pygame.K_k, pygame.K_l, 900, 600)]
     self.map = map.World(self, map_type)
     self.map.generate()
     self.stats = Stats(*self.agents)
     self.state = S_GAME
Пример #2
0
 def continue_game(self):
     self.agents = [Player(self, 'green', pygame.K_d, pygame.K_s, pygame.K_a, pygame.K_w, pygame.K_f, pygame.K_g, 100, 100),
                    Player(self, 'purple', pygame.K_RIGHT, pygame.K_DOWN, pygame.K_LEFT, pygame.K_UP, pygame.K_k, pygame.K_l, 900, 600)]
     self.agents[0].name = self.all_player_names[0]
     self.agents[1].name = self.all_player_names[1]
     self.map = map.World(self, random.choice(self.maps))
     self.map.generate()
     self.state = S_GAME
Пример #3
0
    def new_agent(self, pos, strategy):
        """
        Method that creates a new agent, and adds it to the correct scheduler.
        """
        agent = Player(self.next_id(), self, pos, strategy)

        self.grid.place_agent(agent, pos)
        self.scheduler.add(agent)
Пример #4
0

def eval(model, othermodel):
    wins = 0
    for evaluator in evaluators:
        evaluator.player = model
        evaluator.opponent = othermodel
    results = Parallel(n_jobs=NUM_CORES)(
        delayed(getRes)(evaluators[i], i < NUM_CORES / 2)
        for i in range(NUM_CORES))
    print(results)
    wins = np.sum(results)
    print(argv[1] + ' wins ' + str(wins) + ' games against ' + argv[2])


models = []

for a in argv[1:]:
    print(a)
    if a == 'manual':
        continue
    if a == 'random':
        models.append(Player().to(DEVICE))
    else:
        models.append(torch.load(a).to(DEVICE))

if argv[2] == 'manual':
    models.append(Player().to(DEVICE))
models[0].eval()
models[1].eval()
eval(models[0], models[1])
Пример #5
0
print(DEVICE, num_cores)
vHistory = []
pHistory = []
fig, ax1 = plt.subplots()
ax1.set_xlabel('iterations * 100')
ax1.set_ylabel('Value Loss', color='tab:red')
ax1.tick_params(axis='y', labelcolor='tab:red')
ax2 = ax1.twinx()
ax2.set_ylabel('Policy Loss', color='tab:blue')
ax2.tick_params(axis='y', labelcolor='tab:blue')

if path.exists(BEST_PATH):
    alphazero = torch.load(BEST_PATH)
else:
    alphazero = Player().to(DEVICE)
    torch.save(alphazero, BEST_PATH)

simulators = [Game(alphazero, mctsEnable=True) for c in range(num_cores)]


def genGame(sim, movelimit):
    localdf = pd.DataFrame({
        "States": [],
        "Actions": [],
        "ActionScores": [],
        "Rewards": [],
        "Done": []
    })
    sim.player = alphazero
    for i in range(int(GAMES / num_cores)):