Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.

Commit a7c0d2e

Browse files
committed
Update
1 parent 1b5fc8c commit a7c0d2e

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed
Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
D = [
1+
import numpy as np
2+
3+
D = np.array([
4+
[0, 0, 0, 0, 0, 0, 0, 0, 0],
5+
[0, 0, 0, 0, 0, 0, 0, 0, 0],
26
[0, 0, 0, 0, 0, 0, 0, 0, 0],
37
[0, 0, 0, 0, 0, 0, 0, 0, 0],
48
[0, 0, 0, 0, 0, 0, 0, 0, 0],
59
[0, 0, 0, 0, 0, 0, 0, 0, 0],
610
[0, 0, 0, 0, 0, 0, 0, 0, 0],
711
[0, 0, 0, 0, 0, 0, 0, 0, 0],
812
[0, 0, 0, 0, 0, 0, 0, 0, 0],
9-
]
13+
])
1014

1115

12-
L = [6, 6, 6, 6, 6, 6, 6, 6, 6]
16+
L = [8, 8, 8, 8, 8, 8, 8, 8, 8]
1317

1418

1519
X = {
@@ -18,22 +22,49 @@
1822
2: '#',
1923
}
2024

25+
p1, p2 = 1, 2
26+
2127

2228
def show():
2329
for row in D:
2430
for cell in row:
2531
print(X[cell], end="")
32+
# print(cell, end="")
2633
print()
2734

2835

29-
show()
36+
def check_4(row):
37+
if (np.sum(row) == 4):
38+
print("@ is the winner")
39+
exit()
40+
if (np.sum(row) == 8):
41+
print("# is the winner")
42+
exit()
43+
44+
45+
def check_4_square(M):
46+
for x in [0, 1, 2, 3]:
47+
check_4(M[x])
48+
check_4(M[:, x])
49+
check_4(np.array([M[0, 0], M[1, 1], M[2, 2], M[3, 3]]))
50+
check_4(np.array([M[0, 3], M[1, 2], M[2, 1], M[3, 0]]))
3051

31-
p1, p2 = 1, 2
3252

53+
def check_winner():
54+
for row in range(0, 6):
55+
for col in range(0, 6):
56+
# Div and Conq
57+
M = D[row:row+4, col:col+4]
58+
# print(M)
59+
check_4_square(M)
60+
61+
62+
show()
3363
while True:
3464
i = int(input(f"Enter 1-9: "))
3565
if i >= 1 and i <= 9:
3666
D[L[i-1]][i-1] = p1
3767
L[i-1] -= 1
3868
p1, p2 = p2, p1
3969
show()
70+
check_winner()

0 commit comments

Comments
 (0)