11import random
22import copy
33
4+
45class AI2048 :
56 def __init__ (self , board ):
67 self .board = board
@@ -83,8 +84,10 @@ def calculate_monotonicity(self):
8384 next += 1
8485 if next >= 4 :
8586 next -= 1
86- current_value = 0 if self .board [i ][current ] == 0 else math .log2 (self .board [i ][current ])
87- next_value = 0 if self .board [i ][next ] == 0 else math .log2 (self .board [i ][next ])
87+ current_value = 0 if self .board [i ][current ] == 0 else math .log2 (
88+ self .board [i ][current ])
89+ next_value = 0 if self .board [i ][next ] == 0 else math .log2 (
90+ self .board [i ][next ])
8891 if current_value > next_value :
8992 monotonicity [0 ] += next_value - current_value
9093 elif next_value > current_value :
@@ -100,8 +103,10 @@ def calculate_monotonicity(self):
100103 next += 1
101104 if next >= 4 :
102105 next -= 1
103- current_value = 0 if self .board [current ][j ] == 0 else math .log2 (self .board [current ][j ])
104- next_value = 0 if self .board [next ][j ] == 0 else math .log2 (self .board [next ][j ])
106+ current_value = 0 if self .board [current ][j ] == 0 else math .log2 (
107+ self .board [current ][j ])
108+ next_value = 0 if self .board [next ][j ] == 0 else math .log2 (
109+ self .board [next ][j ])
105110 if current_value > next_value :
106111 monotonicity [2 ] += next_value - current_value
107112 elif next_value > current_value :
@@ -209,11 +214,13 @@ def flip_board(self, board):
209214 def transpose_board (self , board ):
210215 board [:] = [list (i ) for i in zip (* board )]
211216
217+
212218def print_board (board ):
213219 for row in board :
214220 print (row )
215221 print ()
216222
223+
217224if __name__ == "__main__" :
218225 board = [
219226 [0 , 2 , 2 , 4 ],
0 commit comments