Commit ea1fded4 authored by LARIVIERE Axel's avatar LARIVIERE Axel
Browse files

ajout du joueur Random

parent 906acc57
......@@ -19,13 +19,13 @@ class Game:
winner = 0
def __init__(self, joueur1, joueur2, nbPartieDEntrainement=1000):
def __init__(self, joueur1, joueur2, nbPartieDEntrainement=100):
self.joueur1 = joueur1
self.joueur2 = joueur2
self.joueur1.setPlayerNumber(1)
self.joueur2.setPlayerNumber(2)
self.winratej1 = 0
self.winratej2 = 0
self.winratej1 = []
self.winratej2 = []
self.joueur1.setGame(self)
self.joueur2.setGame(self)
self.window = Window(self)
......@@ -39,6 +39,8 @@ class Game:
return self.boardGame
def gameManager(self):
evolution_winratej1 = []
evolution_winratej2 = []
for actualNbGame in range(self.nbPartieDEntrainement):
print("\n <<<< Partie numéro : " + str(actualNbGame) + " >>>>")
while (not self.isEndGame(self.actualPlayer)):
......@@ -51,23 +53,32 @@ class Game:
self.actualPlayer = 1
if self.winner == 1:
self.winratej1 += 1
self.winratej1.append(1)
self.winratej2.append(0)
else:
self.winratej2 += 2
self.winratej1.append(0)
self.winratej2.append(1)
evolution_winratej1.append(np.mean(self.winratej1))
evolution_winratej2.append(np.mean(self.winratej2))
self.joueur1.endGame(self.winner)
self.joueur2.endGame(self.winner)
self.boardGame = [1, 1, 1, 1, 2, 2, 2, 2, 0]
self.winner = 0
self.actualPlayer = 1
print("Player " + str(self.winner) + " win!")
#print("Player " + str(self.winner) + " win!")
#self.window.drawTheScene()
plt.figure(1, figsize=(13, 6))
plt.subplot(1, 2, 1)
plt.plot(range(self.nbPartieDEntrainement), evolution_winratej1, color = 'blue', label="winrate of intelligent agent")
plt.plot(range(self.nbPartieDEntrainement), evolution_winratej2, color = 'red', label="winrate of random agent")
plt.title("winrate of the intelligent agent according to the number of games")
plt.xlabel("number of games")
plt.ylabel("winrate of J1")
if actualNbGame % 100:
print("winrate J1 = " + str(self.winratej1))
print("winrate J2 = " + str(self.winratej2))
def isEndGame(self, nextPlayer): # est ce la fin du jeu? est ce que le prochain joueur peut jouer?
for i in range(9): # pour chaque emplacement de pions
......@@ -171,7 +182,7 @@ class RandomAgent(Player):
def takeDecision(self, game):
print("Au tour de l'IA random")
#print("Au tour de l'IA random")
self.playRandom(game)
......@@ -251,17 +262,18 @@ class Agent(Player):
reward + gamma * self.Q[new_board_game,new_action] - self.Q[actual_board,action])
print("Eps:{:2.4f} Rew:{:2.4f}".format(self.eps, self.total_reward))
# print("Eps:{:2.4f} Rew:{:2.4f}".format(self.eps, self.total_reward))
def takeDecision(self, game):
print("\nAu tour de l'IA intelligente " + str(game.actualPlayer) + ", l'IA joue")
#print("\nAu tour de l'IA intelligente " + str(game.actualPlayer) + ", l'IA joue")
self.SARSA()
def showEndingResult(self):
#x = np.range(0, self.game.nbPartieDEntrainement)
#print("nb partie entrainement : "+str(self.game.nbPartieDEntrainement))
plt.subplot(1, 2, 2)
plt.plot(range(self.game.nbPartieDEntrainement), self.epsData, label = "eps for each Game")
plt.title('eps for each Game')
plt.xlabel('number of game', fontsize=14)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment