-
Notifications
You must be signed in to change notification settings - Fork 5
/
feature_reader.py
52 lines (41 loc) · 1.21 KB
/
feature_reader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import math
def get_variance(board):
# FIXME: code me
return 0
def mergeable_tiles(board, direction):
# FIXME: code me
return 0
def get_histograms(board):
xhisto = [0, 0, 0, 0]
yhisto = [0, 0, 0, 0]
for x in range(0, 4):
for y in range(0, 4):
if board[x][y]:
xhisto[y] += math.log(board[x][y], 2)
yhisto[x] += math.log(board[x][y], 2)
return (xhisto, yhisto)
def get_features_limits():
features_limits = []
for i in range(0, 8):
features_limits.append([0, 40])
# for i in range(0, 5):
# features_limits.append([0, 0])
return features_limits
def extract_features(board):
# Dim(set) = 13
features = []
# Vertical/horizontal density extraction
# Dim = 8
(xdensity, ydensity) = get_histograms(board)
for density in xdensity:
features.append(density)
for density in ydensity:
features.append(density)
# Number of close mergeable tiles for each direction
# Dim = 4
# for direction in range(0, 4):
# features.append(mergeable_tiles(board, direction))
# Variance of the board
# Dim = 1
# features.append(get_variance(board))
return features