Commit 904a8808 authored by DUFAIX Clement's avatar DUFAIX Clement
Browse files

add better eps

parent ea1fded4
......@@ -19,7 +19,7 @@ class Game:
winner = 0
def __init__(self, joueur1, joueur2, nbPartieDEntrainement=100):
def __init__(self, joueur1, joueur2, nbPartieDEntrainement=1000):
self.joueur1 = joueur1
self.joueur2 = joueur2
self.joueur1.setPlayerNumber(1)
......@@ -225,8 +225,8 @@ class Agent(Player):
temp = self.greedy(Q, s)
return temp
def SARSA(self, lr=0.01, num_episode=10000, eps=0.5, gamma=0.95, eps_decay=0.001):
def SARSA(self, lr=0.01, num_episode=10000, eps=0.5, gamma=0.95, eps_decay=0.00001):
self.eps_decay = eps_decay
ini_board = self.game.getBoardGame()
actual_board = ''
for i in ini_board:
......@@ -250,6 +250,8 @@ class Agent(Player):
if not played:
reward = -10
if self.eps < 0.99:
self.eps -= reward * self.eps_decay
self.total_reward += reward
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])
......@@ -257,6 +259,8 @@ class Agent(Player):
action = new_action
reward = 20
if self.eps > 0.01:
self.eps -= reward * self.eps_decay
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])
......@@ -285,6 +289,8 @@ class Agent(Player):
if playerWinning == self.position:
self.reward = 200
self.total_reward += self.reward
if self.eps > 0.01:
self.eps -= self.reward * self.eps_decay
#print("j'ai gagné !")
#input()
else:
......@@ -292,6 +298,8 @@ class Agent(Player):
self.total_reward += self.reward
#print("j'ai perdu ...")
#input()
if self.eps < 0.99:
self.eps -= self.reward * self.eps_decay
class Window(QMainWindow):
index = 0
......@@ -380,4 +388,6 @@ class Window(QMainWindow):
if __name__ == "__main__":
app = QApplication(sys.argv)
Game(Agent(), RandomAgent())
agent = Agent()
Game(agent, RandomAgent())
Game(RealPlayer(), agent, 5)
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