-
Notifications
You must be signed in to change notification settings - Fork 8
/
block.py
95 lines (72 loc) · 1.62 KB
/
block.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from __future__ import print_function
import signal,copy,sys,time
from random import randint
from board import *
class Block(Board):
def rotate(self,sc,bl):
rs=[]
cs=[]
for i in bl:
rs.append(i[0])
cs.append(i[1])
mnr=40
mnc=40
mxr=0
mxc=0
for i in rs:
mnr= i if i<mnr else mnr
mxr= i if mxr<i else mxr
for i in cs:
mnc= i if mnc>i else mnc
mxc= i if mxc<i else mxc
tmp = [[0 for x in range(mxc-mnc +1)] for y in range(mxr-mnr+1)]
for i in bl:
xc=i[0]-mnr
yc=i[1]-mnc
tmp[xc][yc]=1
nbl=zip(*tmp[::-1])
ch=0
for i in range(mxr-mnr+1):
for j in range(mxc - mnc +1):
if(nbl[j][i]==1):
ch= ch + self.checkPiecePos(mnr+j,mnc+i,sc)
ret=[]
if (ch!=0):
return ret
for i in range(mxr-mnr+1):
for j in range(mxc - mnc +1):
if(nbl[j][i]==1):
ret.append([mnr+j,mnc+i])
return ret
def moveRight(self,sc,bl):
ch = 0
for p in bl:
ch = ch + self.checkPiecePos(p[0],p[1]+1,sc)
if (ch==0):
for p in bl:
p[1]=p[1]+1
return 0
def Down(self,sc,bl):
ch = 0
for p in bl:
ch = ch + self.checkPiecePos(p[0]+1,p[1],sc)
if (ch!=0):
for p in bl:
sc[p[0]][p[1]]=1
return 1
for p in bl:
p[0]=p[0]+1
return 0
def moveLeft(self,sc,bl):
ch = 0
for p in bl:
ch = ch + self.checkPiecePos(p[0],p[1]-1,sc)
if (ch==0):
for p in bl:
p[1]=p[1]-1
return 0
def draw(self,sc,bl):
while(1):
a = self.Down(sc,bl)
if (a==1):
return 1