-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoring_functions.py
54 lines (49 loc) · 1.33 KB
/
scoring_functions.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
53
54
import numpy as np
def get_heights(matrix):
counts = []
count = 0
for i in range(10):
for n in range(18):
if matrix[n, i] == 0:
count += 1
else:
if count != 0:
count = abs(count - 18)
counts.append(count)
count = 0
break
return counts
def aggregate_height(matrix):
return sum(get_heights(matrix))
def calculate_bumpiness(matrix):
counts = get_heights(matrix)
bumpiness = 0
for m in range(1, 10):
bumpiness += abs(counts[m-1]-counts[m])
return bumpiness
def lines_cleared_at_same_time(matrix):
lines_cleared = 0
count = 0
for n in range(18):
for i in range(10):
if matrix[n, i] == 1:
count += 1
if count == 10:
lines_cleared += 1
count = 0
else:
count = 0
break
return lines_cleared
def recognize_holes(matrix):
first_block = False
count = 0
for i in range(10):
for n in range(18):
if matrix[n, i] == 1:
first_block = True
if first_block == True:
if matrix[n, i] == 0:
count += 1
first_block = False
return count