-
-
Save jamad/6dc4eae34a1375aa80135ff446d971a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_check(B): | |
def f(r,c,u,v): | |
T=[] | |
for i in range(1,8): | |
p=(r+i*u,c+i*v) | |
if D.get(p,' ')in'♛♝♞♜♟':break | |
T+=[p] | |
return T | |
D={} | |
for r in range(8): | |
for c in range(8): | |
if B[r][c]=='♔':k=(r,c) | |
D[(r,c)]=B[r][c] | |
for r,c in D: | |
S,e=[],D[(r,c)] | |
if e=='♛':S+=[(r-1,c-1),(r-1,c),(r-1,c+1),(r,c-1),(r,c+1),(r+1,c-1),(r+1,c),(r+1,c+1)] | |
if e in'♝♛':S+=f(r,c,1,1)+f(r,c,-1,-1)+f(r,c,-1,1)+f(r,c,1,-1) | |
if e=='♞':S+=[(r-2,c-1),(r-2,c+1),(r-1,c+2),(r+1,c+2),(r+2,c-1),(r+2,c+1),(r-1,c-2),(r+1,c-2)] | |
if e in'♜♛':S+=f(r,c,1,0)+f(r,c,-1,0)+f(r,c,0,1)+f(r,c,0,-1) | |
if e=='♟':S+=[(r+1,c-1),(r+1,c+1)] | |
if k in S:return 1 | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment