def selectPlayers(self): if self.playerBlack == 2: self.agentBlack = ag.RandomAgent(2) elif self.playerBlack == 3: self.agentBlack = ag.RulesAgent(2) elif self.playerBlack == 4: self.agentBlack = ag.RulesPriorityAgent(2) elif self.playerBlack == 5: self.agentBlack = ag.UnionRulesAgent(2) elif self.playerBlack == 6: self.agentBlack = ag.AlphaBetaAgent(2, 4, self.evaluator1) elif self.playerBlack == 7: self.agentBlack = ag.MinimaxAgent(2, 5, self.evaluator1) elif self.playerBlack == 8: self.agentBlack = ag.MonteCarloAgent(2, 60) if self.playerWhite == 2: self.agentWhite = ag.RandomAgent(1) elif self.playerWhite == 3: self.agentWhite = ag.RulesPriorityAgent(1) elif self.playerWhite == 4: self.agentWhite = ag.RulesPriorityAgent(1) elif self.playerWhite == 5: self.agentWhite = ag.RulesPriorityAgent(1) elif self.playerWhite == 6: self.agentWhite = ag.AlphaBetaAgent(1, 4, self.evaluator2) elif self.playerWhite == 7: self.agentWhite = ag.MinimaxAgent(1, 5, self.evaluator2) elif self.playerWhite == 8: self.agentWhite = ag.MonteCarloAgent(1, 60)
def getFitness(self, matrix): ev1_1 = ev.Evaluator(1, matrix) ev2_1 = ev.Evaluator(2) ag1_1 = ag.AlphaBetaAgent(1, 2, ev1_1) ag2_1 = ag.AlphaBetaAgent(2, 2, ev2_1) result1, game1 = self.simulateGame(ag1_1, ag2_1) white, black = game1.countColors() if black == 0: fitness1 = 64 elif white == 0: fitness1 = -64 else: fitness1 = white - black ev1_2 = ev.Evaluator(1, matrix) ev2_2 = ev.Evaluator(2) ag2_2 = ag.AlphaBetaAgent(1, 2, ev2_2) ag1_2 = ag.AlphaBetaAgent(2, 2, ev1_2) result2, game2 = self.simulateGame(ag2_2, ag1_2) white, black = game2.countColors() if black == 0: fitness2 = -64 elif white == 0: fitness2 = 64 else: fitness2 = black - white fitness = (fitness1 + fitness2) return fitness
def simulateAlpha(): ev1 = ev.Evaluator(1) ev2 = ev.Evaluator(1) """#Alfabeta vs Union ag1 = ag.AlphaBetaAgent(1,4,ev1) ag2 = ag.UnionRulesAgent(2) sim = Simulation(ag1, ag2, 250, 1) # Union vs Alfabeta ag1 = ag.UnionRulesAgent(1) ag2 = ag.AlphaBetaAgent(2,4,ev1) sim = Simulation(ag1, ag2, 250, None, 1)""" # Determinista # Alfabeta vs Minimax ag1 = ag.AlphaBetaAgent(1, 4, ev1) ag2 = ag.MinimaxAgent(2, 4, ev2) sim = Simulation(ag1, ag2, 1, 1, 1) # Minimax vs Alfabeta ag1 = ag.MinimaxAgent(1, 4, ev2) ag2 = ag.AlphabetaAgent(2, 4, ev1) sim = Simulation(ag1, ag2, 1, 1, 1) #Alfabeta vs MCTS ag1 = ag.AlphaBetaAgent(1, 4, ev1) ag2 = ag.MonteCarloAgent(2, None) sim = Simulation(ag1, ag2, 250, 1) # MCTS vs Alfabeta ag1 = ag.MonteCarloAgent(1, None) ag2 = ag.AlphaBetaAgent(2, 4, ev1) sim = Simulation(ag1, ag2, 250, None, 1)
def simulateEvaluator(): # Alfabeta vs alfabeta variando evaluator for i in range(1, 7): for j in range(1, 7): if i != j: sim = Simulation(ag.AlphaBetaAgent(1, 4, ev.Evaluator(i)), ag.AlphaBetaAgent(2, 4, ev.Evaluator(j)), 1, i, j)
def simulateDepthM(): ev1 = ev.Evaluator(1) ev2 = ev.Evaluator(1) for i in range(1, 9): sim = Simulation(ag.MinimaxAgent(1, i, ev1), ag.AlphaBetaAgent(2, 4, ev2), 1, "", 1) sim = Simulation(ag.AlphaBetaAgent(1, 4, ev2), ag.MinimaxAgent(2, i, ev1), 1, 1, "")
def resultSimulate(self, matrix1, matrix2): ev1_1 = ev.Evaluator(1, matrix1) ev2_1 = ev.Evaluator(1, matrix2) ag1_1 = ag.AlphaBetaAgent(1, 4, ev1_1) # ind1 -> Blanco ag2_1 = ag.AlphaBetaAgent(2, 4, ev2_1) # ind2 -> Negro simulate1 = self.simulateGame(ag1_1, ag2_1) a1w, a2b, d1 = 0, 0, 0 if (simulate1 == 2): a2b += 1 elif (simulate1 == 1): a1w += 1 else: d1 += 1 ev1_2 = ev.Evaluator(1, matrix1) ev2_2 = ev.Evaluator(1, matrix2) ag1_2 = ag.AlphaBetaAgent(2, 4, ev1_2) # ind1 -> Negro ag2_2 = ag.AlphaBetaAgent(1, 4, ev2_2) # ind2 -> Blanco simulate2 = self.simulateGame(ag2_2, ag1_2) a2w, a1b, d2 = 0, 0, 0 if (simulate2 == 2): a1b += 1 elif (simulate2 == 1): a2w += 1 else: d2 += 1 a1 = a1w + a1b a2 = a2w + a2b d = d1 + d2 if a1 > a2: return matrix1, 1 elif a2 > a1: return matrix2, 2 else: random = randint(0, 1) if random == 0: return matrix1, -1 else: return matrix2, -2