-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession17(b).py
More file actions
107 lines (84 loc) · 2.1 KB
/
session17(b).py
File metadata and controls
107 lines (84 loc) · 2.1 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import numpy as np
board = np.zeros((8, 8))
print(board)
# 1. Creation of a Chess Board
for i in range(0, 8):
for j in range(0, 8):
board[i][j] = (i+j) % 2
print()
print()
print(board)
# 2. Place the no. of queens on the desired position
print()
l=[]
flag = True
print("Enter how many queens do u want to place:")
n = int(input())
for g in range(0, n):
print("Enter the position:")
p = input()
x = int(p[0])
y = int(p[2])
i = x-1
j = y-1
k = x+1
o = y+1
# 3. Check whether a queen is placed in the diagonal where a queen is already existing
# Lower Right Diagonal
while k < 7 and o < 8:
if board[k][o] == 9:
flag = False
print("Queen already existing in the lower right diagonal !!")
break
k = k + 1
o = o + 1
# Upper Left Diagonal
while i > 0 and j > 0:
if board[i][j] == 9:
flag = False
print("Queen already existing in the upper left diagonal !!")
break
i = i-1
j = j-1
a = x-1
b = y+1
c = x+1
d = y-1
# Upper Right Diagonal
while a >= 0 and b < 7:
if board[a][b] == 9:
flag = False
print("Queen already existing in the upper right diagonal !!")
break
a = a-1
b = b+1
# Lower Left Diagonal
while c < 7 and d >= 0:
if board[c][d] == 9:
flag = False
print("Queen already existing in the lower left diagonal !!")
break
a = c + 1
d = d - 1
# 4.Check whether queen is placed in row or column where a queen is already existing
if x in l :
print("Already a queen in same row !!")
flag = False
elif y in l:
print("Already a queen in same column !!")
flag = False
else:
#print("Can enter !!")
#print(x)
#print(y)
board[x][y] = 9
l.append(x)
l.append(y)
if flag == False:
print("Cannot enter!!")
else:
print("Can enter!!")
board[x][y] = 9
print()
print()
print(board)