-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect.py
More file actions
43 lines (39 loc) · 1.4 KB
/
connect.py
File metadata and controls
43 lines (39 loc) · 1.4 KB
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
import sys
X, Y, N = map(int, input().split())
board = [["O"]*Y for _ in range(X)]
for x in range(X):
row = input().strip().split()
board[x] = row
def checkForWin ( row, col ):
winstatus = False
global x
global y
global N
dirX = [1 , 0, -1, 0, -1, 1, -1, 1]
dirY = [0 , 1, 0, -1, -1, 1, 1, -1]
for i in range(8):
xdir = dirX[i]
ydir = dirY[i]
if (row+((N-1)*xdir) >= 0 ) and (row+((N-1)*xdir) < X ) and (col+((N-1)*ydir) >= 0 ) and (col+((N-1)*ydir) < Y ):
winstatus = True
for t in range(N):
# print(board[row+(t*xdir)][col+(t*ydir)] +"--"+board[row][col])
# print(str(row+(t*xdir))+","+str(col+(t*ydir)) +"--"+str(row)+","+str(col))
if board[row+(t*xdir)][col+(t*ydir)] != board[row][col]:
# print("row " + str(row+(t*xdir)) + " " + str(row))
# print("col " + str(col+(t*ydir)) + " " + str(col))
winstatus = False
break
if winstatus == True:
break
return winstatus
for x in range(X):
for y in range(Y):
if(board[x][y] in ["B", "R"]):
if checkForWin(row=x, col=y):
if board[x][y] == "B":
print("BLUE WINS")
else:
print("RED WINS")
sys.exit(0)
print("NONE")