Commit b5c7af9a authored by Antoine Roux's avatar Antoine Roux
Browse files

cleaned a bit, added comments

parent 6d7998a2
...@@ -161,6 +161,10 @@ class Grid (object) : ...@@ -161,6 +161,10 @@ class Grid (object) :
""" Returns the fitness of the grid """ Returns the fitness of the grid
""" """
# fitnessArray = [[64, 16, 4, 1], #a peu près pareil
# [256, 64, 16, 4],
# [1024, 256, 64, 16],
# [4096, 1024, 256, 64]]
fitnessArray = [[8, 4, 2, 1], fitnessArray = [[8, 4, 2, 1],
[16, 8, 4, 2], [16, 8, 4, 2],
[32, 16, 8, 4], [32, 16, 8, 4],
...@@ -207,10 +211,10 @@ def single_AI() : ...@@ -207,10 +211,10 @@ def single_AI() :
myGrid.addNbr() myGrid.addNbr()
while True : while True :
fitnessArray = np.array([[0,0,0,0], #lignes = à 1er move constant fitnessArray = np.array([[0, 0, 0, 0], #lignes = à 1er move constant
[0,0,0,0], [0, 0, 0, 0],
[0,0,0,0], [0, 0, 0, 0],
[0,0,0,0]]) [0, 0, 0, 0]])
tempGrid = Grid(myGrid.grid) #c'est peut être ça qui est très lent tempGrid = Grid(myGrid.grid) #c'est peut être ça qui est très lent
for k in range(4) : for k in range(4) :
...@@ -234,13 +238,28 @@ def single_AI() : ...@@ -234,13 +238,28 @@ def single_AI() :
for k in range (4) : for k in range (4) :
maxArray[k] = max(fitnessArray[k]) maxArray[k] = max(fitnessArray[k])
# maxArray[k] = fitnessArray[k].mean() #moins bon que le max # maxArray[k] = fitnessArray[k].mean() #moins bon que le max
#we reverse the array to make sure the default swipe is left and not up
reversedMaxArray = maxArray[::-1]
direction = maxArray.index(max(maxArray)) direction = maxArray.index(max(maxArray))
if direction == 0 :
direction == 3
elif direction == 1 :
direction == 2
elif direction == 2 :
direction == 1
elif direction == 3 :
direction == 0
myGrid.swipe(direction) myGrid.swipe(direction)
myGrid.addNbr() myGrid.addNbr()
except : except :
return(myGrid.grid) return(myGrid.grid)
break break
#user_input = input()
#useful for debugging and seeing what is happening
# print(myGrid)
# user_input = input()
############################################## ##############################################
...@@ -288,7 +307,7 @@ if MODE == "AI" : ...@@ -288,7 +307,7 @@ if MODE == "AI" :
if MODE == "MULTI_AI" : if MODE == "MULTI_AI" :
startTime = time.time() startTime = time.time()
nbrGames = 10 nbrGames = 100
listScores = [[],[]] listScores = [[],[]]
for k in range(nbrGames) : for k in range(nbrGames) :
finishedGrid = single_AI() finishedGrid = single_AI()
...@@ -304,7 +323,7 @@ if MODE == "MULTI_AI" : ...@@ -304,7 +323,7 @@ if MODE == "MULTI_AI" :
print("Temps écoulé :", int((endTime-startTime)*1000), "ms") print("Temps écoulé :", int((endTime-startTime)*1000), "ms")
print(np.array(listScores)) print(np.array(listScores))
print("--------------------------") print("--------------------------")
#plot a bar graph
# width = 30 width = 30
# plt.bar(listScores[0], listScores[1], width) plt.bar(listScores[0], listScores[1], width)
# plt.show() plt.show()
No preview for this file type
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