Commit 906acc57 authored by DUFAIX Clement's avatar DUFAIX Clement
Browse files

add plot for eps

parent de3f79ea
......@@ -8,6 +8,8 @@ from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import random
import array as ar
import matplotlib.pyplot as plt
import numpy as np
class Game:
......@@ -17,7 +19,7 @@ class Game:
winner = 0
def __init__(self, joueur1, joueur2, nbPartie=10000):
def __init__(self, joueur1, joueur2, nbPartieDEntrainement=1000):
self.joueur1 = joueur1
self.joueur2 = joueur2
self.joueur1.setPlayerNumber(1)
......@@ -27,15 +29,17 @@ class Game:
self.joueur1.setGame(self)
self.joueur2.setGame(self)
self.window = Window(self)
self.nbPartie = nbPartie
self.nbPartieDEntrainement = nbPartieDEntrainement
self.gameManager()
self.joueur1.showEndingResult()
self.joueur2.showEndingResult()
input() # fin du jeu
def getBoardGame(self):
return self.boardGame
def gameManager(self):
for actualNbGame in range(self.nbPartie):
for actualNbGame in range(self.nbPartieDEntrainement):
print("\n <<<< Partie numéro : " + str(actualNbGame) + " >>>>")
while (not self.isEndGame(self.actualPlayer)):
self.window.drawTheScene()
......@@ -50,10 +54,12 @@ class Game:
self.winratej1 += 1
else:
self.winratej2 += 2
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!")
#self.window.drawTheScene()
......@@ -118,9 +124,16 @@ class Player():
def takeDecision(self, game):
pass
def showEndingResult(self):
pass
def setPlayerNumber(self, position):
self.position = position
def endGame(self, playerWinning):
pass
class RealPlayer(Player):
def takeDecision(self, game):
......@@ -175,6 +188,7 @@ class Agent(Player):
self.gamma = gamma
self.eps_decay = eps_decay
self.tour = 0
self.epsData = []
def setGame(self, game):
self.game = game
......@@ -233,29 +247,39 @@ class Agent(Player):
reward = 20
self.isWinner(self.game)
self.Q[actual_board,action] = self.Q[actual_board,action] + self.lr * (
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))
def isWinner(self, game): #problème ici il ne rentre jamais dans le if
if game.isEndGame(game.actualPlayer):
self.reward = 200
self.total_reward += self.reward
print("t'as gagné !")
input()
else:
self.reward = -100
self.total_reward += self.reward
print("t'as perdu !")
input()
def takeDecision(self, game):
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.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)
plt.ylabel('eps', fontsize=14)
plt.show()
def endGame(self, playerWinning):
self.epsData.append(self.eps)
if playerWinning == self.position:
self.reward = 200
self.total_reward += self.reward
#print("j'ai gagné !")
#input()
else:
self.reward = -100
self.total_reward += self.reward
#print("j'ai perdu ...")
#input()
class Window(QMainWindow):
index = 0
......
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