-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpossiblequeen.py
More file actions
168 lines (168 loc) · 4.76 KB
/
Copy pathpossiblequeen.py
File metadata and controls
168 lines (168 loc) · 4.76 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import numpy as np
class PossibleQueen():
def __init__(self,n):
self.n=n
self.current_chess_board=np.zeros([n,n],dtype="int64")
self.logic_chess_board=np.zeros([n,n],dtype="int64")
def dialu(self,x,y):
xc=x
yc=y
xa=[]
ya=[]
while xc!=0:
xc=xc-1
xa.append(xc)
while yc!=0:
yc=yc-1
ya.append(yc)
result=[]
max_result=min(len(xa),len(ya))
for i in range(0,max_result):
result.append([xa[i],ya[i]])
return result
def diaru(self,x,y):
xc=x
yc=y
xa=[]
ya=[]
while xc!=0:
xc=xc-1
xa.append(xc)
while yc!=self.n-1:
yc=yc+1
ya.append(yc)
result=[]
max_result=min(len(xa),len(ya))
for i in range(0,max_result):
result.append([xa[i],ya[i]])
return result
def diarl(self,x,y):
xc=x
yc=y
xa=[]
ya=[]
while xc!=self.n-1:
xc=xc+1
xa.append(xc)
while yc!=self.n-1:
yc=yc+1
ya.append(yc)
result=[]
max_result=min(len(xa),len(ya))
for i in range(0,max_result):
result.append([xa[i],ya[i]])
return result
def diall(self,x,y):
xc=x
yc=y
xa=[]
ya=[]
while xc!=self.n-1:
xc=xc+1
xa.append(xc)
while yc!=0:
yc=yc-1
ya.append(yc)
result=[]
max_result=min(len(xa),len(ya))
for i in range(0,max_result):
result.append([xa[i],ya[i]])
return result
def linleft(self,x,y):
yc=y
xa=[x for xe in range(0,y)]
ya=[]
result=[]
while yc!=0:
yc=yc-1
ya.append(yc)
for i in range(0,len(xa)):
result.append([xa[i],ya[i]])
return(result)
def linupper(self,x,y):
xc=x
ya=[y for xe in range(0,x)]
xa=[]
result=[]
while xc!=0:
xc=xc-1
xa.append(xc)
for i in range(0,len(xa)):
result.append([xa[i],ya[i]])
return(result)
def linright(self,x,y):
yc=y
xa=[x for ye in range(y+1,self.n)]
ya=[]
result=[]
while yc!=7:
yc=yc+1
ya.append(yc)
for i in range(0,len(xa)):
result.append([xa[i],ya[i]])
return(result)
def linlower(self,x,y):
xc=x
ya=[y for xe in range(x+1,self.n)]
xa=[]
result=[]
while xc!=7:
xc=xc+1
xa.append(xc)
for i in range(0,len(ya)):
result.append([xa[i],ya[i]])
return(result)
def fill_lu(self,x,y):
for i,j in self.dialu(x,y):
self.logic_chess_board[i][j]=1
def fill_ru(self,x,y):
for i,j in self.diaru(x,y):
self.logic_chess_board[i][j]=1
def fill_rl(self,x,y):
for i,j in self.diarl(x,y):
self.logic_chess_board[i][j]=1
def fill_ll(self,x,y):
for i,j in self.diall(x,y):
self.logic_chess_board[i][j]=1
def fill_left(self,x,y):
for i,j in self.linleft(x,y):
self.logic_chess_board[i][j]=1
def fill_upper(self,x,y):
for i,j in self.linupper(x,y):
self.logic_chess_board[i][j]=1
def fill_right(self,x,y):
for i,j in self.linright(x,y):
self.logic_chess_board[i][j]=1
def fill_lower(self,x,y):
for i,j in self.linlower(x,y):
self.logic_chess_board[i][j]=1
def fill_center(self,x,y):
self.logic_chess_board[x][y]=1
def isPossible(self,x,y):
if self.logic_chess_board[x][y]==1:
return False
return True
def return_logic_chess_board(self,):
return self.logic_chess_board
def return_current_chess_board(self,):
return self.current_chess_board
def return_queen(self,):
count=0
for i in self.current_chess_board:
for j in i:
if(j==1):
count=count+1
return count
def fill(self,xx,yy):
self.fill_center(xx,yy)
self.fill_left(xx,yy)
self.fill_upper(xx,yy)
self.fill_right(xx,yy)
self.fill_lower(xx,yy)
self.fill_lu(xx,yy)
self.fill_ru(xx,yy)
self.fill_rl(xx,yy)
self.fill_ll(xx,yy)
self.place_queen_current_chess_board(xx,yy)
def place_queen_current_chess_board(self,x,y):
self.current_chess_board[x][y]=1