-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStringToBoardTest.py
40 lines (29 loc) · 1.84 KB
/
StringToBoardTest.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
board1 = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000100000000010000000001000000000100000010010001001001101111110111111111011111111101111111110"
board2 = "00000000000000000000000000000000000000000000000000000000000010000000001000000000100000000010000000001000000000100000000010000000001000000000100000010010001001001101111110111111111011111111101111111110"
# https://stackrabbit.herokuapp.com/rate-move?board=00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000100000000010000000001000000000100000010010001001001101111110111111111011111111101111111110&secondBoard=00000000000000000000000000000000000000000000000000000000000010000000001000000000100000000010000000001000000000100000000010000000001000000000100000010010001001001101111110111111111011111111101111111110?currentPiece=I&nextPiece=O&level=18&lines=8&inputFrameTimeline=X.....&lookaheadDepth=1
import numpy as np
def lineClear(array):
# This yields a list of all the rows that are not filled
nonFilledRows = np.where((1-array).any(axis=1))[0]
# no line clear
if len(nonFilledRows) == 20:
return array, 0
# Nice numpy trick which stores all the non-filled rows in a list.
newBoard = array[nonFilledRows]
numFilled = 20 - len(nonFilledRows)
# All you need to do now is insert rows at the top to complete line clear computation.
for i in range(numFilled):
newBoard = np.insert(newBoard, 0, np.array([0,0,0,0,0,0,0,0,0,0]),0 )
assert(len(newBoard) == 20)
return newBoard, numFilled
b1 = [0 if s == "0" else 1 for s in board1]
b2 = [0 if s == "0" else 1 for s in board2]
b1 = np.reshape(b1,(20,10))
b2 = np.reshape(b2,(20,10))
print(len(board1))
print(len(board2))
print(b1)
print(b2)
num, b3 = lineClear(b2)
print()
print(b1+b2)