Skip to content

Commit ab8fe5a

Browse files
add expectiminimax2
1 parent d068aaa commit ab8fe5a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

AI.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, GameBoard, level):
1818
"expert",
1919
][level]
2020

21-
'''
21+
"""
2222
Weight board assign the grids on board with weight
2323
in zigzag order increasing exponentially with base 4
2424
e.g. for a weight board with size 4, the board weight is
@@ -28,8 +28,8 @@ def __init__(self, GameBoard, level):
2828
[4^15, 4^14, 4^13, 4^12]]
2929
3030
Reference: http://cs229.stanford.edu/proj2016/report/NieHouAn-AIPlays2048-report.pdf
31-
'''
32-
31+
"""
32+
3333
def weightBoard1(size):
3434
board = [[(row * size + col) for col in range(size)] for row in range(size)]
3535
for row in range(size):
@@ -405,11 +405,11 @@ def minnieMoveAlphaBetaImportance(self, depth, alpha, beta, importance, evalFunc
405405
return evalFunc(), None # depth = 0
406406

407407
originalScore = self.GameBoard.score
408-
'''
408+
"""
409409
Even though the real computer will put the new numbers randomly,
410410
we still assume that it can put 2 or 4 on any empty tile as it
411411
wishes to make the board harder for player to solve.
412-
'''
412+
"""
413413

414414
# mark the empty tiles with highest importances as "important"
415415
importantTiles = self.getImporantTiles(importance)
@@ -457,6 +457,7 @@ def getMaxMove3(self):
457457
the product of the current board score and the sum of the product of weight of a certain tile and the number on it.
458458
(i.e. GameBoard.score * ∑(row)∑(col) weightBoard[row][col] * GameBoard[row][col])
459459
"""
460+
460461
def evaluate2(self):
461462
score = 0
462463
for row in range(self.size):
@@ -587,4 +588,4 @@ def playTheGame(self):
587588
# print("average score: ", avgscore)
588589
# winrate = sum(winLose) / len(record)
589590
# print("winrate: ", winrate)
590-
# print("---Total time: %s seconds ---" % (time.time() - startTime))
591+
# print("---Total time: %s seconds ---" % (time.time() - startTime))

0 commit comments

Comments
 (0)