forked from VisionOra/Python-django-chess-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPawn.py
39 lines (31 loc) · 1.16 KB
/
Pawn.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 Pawn(Piece):
"""
Pawn class inherit from Piece
"""
def canMove(self,board,x,y,turn):
"""
param x : take the target x-axis coordinate
param y : take the target y-axis coordinate
param turn: from 1,2 you will know which player turn it is 1 = White, 2 = Black
"""
sourceX,sourceY,targetX,targetY=self.x,self.y,x,y
# turn 1 == white player
if turn==1:
"""
check if the source is greater and the subtraction is < 2 and > 0
so the pawn can only more one or two steps
"""
if sourceX > targetX and (abs(sourceX - targetX) == 1
or abs(sourceX - targetX) == 2):
return True
else:
return False
# turn 2 == Black player
elif turn==2:
# same as white but in opposite direction
if sourceX < targetX and (abs(sourceX - targetX) == 1
or abs(sourceX - targetX) == 2):
return True
else:
return False