1
1
import random
2
2
import copy
3
3
4
+
4
5
class AI2048 :
5
6
def __init__ (self , board ):
6
7
self .board = board
@@ -83,8 +84,10 @@ def calculate_monotonicity(self):
83
84
next += 1
84
85
if next >= 4 :
85
86
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 ])
88
91
if current_value > next_value :
89
92
monotonicity [0 ] += next_value - current_value
90
93
elif next_value > current_value :
@@ -100,8 +103,10 @@ def calculate_monotonicity(self):
100
103
next += 1
101
104
if next >= 4 :
102
105
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 ])
105
110
if current_value > next_value :
106
111
monotonicity [2 ] += next_value - current_value
107
112
elif next_value > current_value :
@@ -209,11 +214,13 @@ def flip_board(self, board):
209
214
def transpose_board (self , board ):
210
215
board [:] = [list (i ) for i in zip (* board )]
211
216
217
+
212
218
def print_board (board ):
213
219
for row in board :
214
220
print (row )
215
221
print ()
216
222
223
+
217
224
if __name__ == "__main__" :
218
225
board = [
219
226
[0 , 2 , 2 , 4 ],
0 commit comments