-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht.5stone.py
More file actions
56 lines (46 loc) · 1021 Bytes
/
t.5stone.py
File metadata and controls
56 lines (46 loc) · 1021 Bytes
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
board=[[' ' for i in range(10)] for j in range(10)]
def isEmpty(x):
return x == ' '
def isSame(x1,x2):
return x1 == x2
def getNext(brd,x,y,vx,vy):
if (x+vx) != -1 and (x+vx) != 10 and (y+vy) != -1 and (y+vy) != 10:
return brd[x+vx][y+vy]
else:
return ' '
def getLen(brd,x,y,vx,vy):
len=0
if !isEmpty(brd[x][y]):
while isSame(brd[x][y],getNext(brd,x,y,vx,vy)):
len+=1
x+=vx
y+=vy
return len
def getFullLen(brd,x,y):
direct=[[1,0],[-1,0],[0,1],[0,-1],[1,1],[-1,-1],[-1,1],[1,-1]] # 8 direction
lens=[]
for i in range(1,7,2):
len1=getLen(brd,x,y,direct[i][0],direct[i][1])
len2=getLen(brd,x,y,direct[i+1][0],direct[i+1][1])
lens.append(len1+len2+1)
return lens
def has5stone(lens):
for l in lens:
if l==5:
return True
return False
def move(brd,x,y,clr):
if isEmpty(brd[x][y]):
brd[x][y]=clr
return True
else:
return False
def showLine(brd,x):
s=''+str(x)
for i in brd[x]:
s+=i
print(s)
def show(brd):
print("_0123456789")
for x in range(10):
showLine(brd,x)