-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQueen.py
39 lines (34 loc) · 1.1 KB
/
Queen.py
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
from Piece import Piece
class Queen(Piece):
'''
Queen Class inherited from Piece
'''
def canAttack(self,board,piece):
'''
Bonus func to check weather a queen can kill other queen
'''
sourceX,sourceY,targetX,targetY=self.x,self.y,piece.x,piece.y
if sourceX==targetX or sourceY==targetY:
return True
elif abs(sourceX-targetX)==abs(sourceY-targetY):
return True
else:
return False
def canMove(self,board,x,y):
'''
This func will return weather a queen can move to provided x,y or not
Input: Board and targer co-ordinates
Output: Boolean result
'''
sourceX,sourceY,targetX,targetY=self.x,self.y,x,y
#move in same row
if sourceX==targetX and sourceY!=targetY:
return True
#move in same col
elif sourceX!=targetX and sourceY==targetY:
return True
#diagnonal move
elif abs(sourceX-targetX)==abs(sourceY-targetY):
return True
else:
return False