I think the original proposal as well as the answers so far are missing/reproducing what I'd consider as a main default: The programs are much more complicated than the problem would require. We have a specific problem, and its specificities should be 'exploited' in a smart way to provide an elegant, lean solution. IMHO it is "bloatware" to have so many definitions (list of files, ranks, possible moves...) or to try to make a program that can solve problems other than the given one. The problem literally translates to a simple increment statement within a loop over all squares, and a few "one-liner" helper functions to know which counter must be incremented: ``` def amazonCheckmate(king: str, amazon: str): """Return [c0,c1,c2,c3] where the four components count the number of squares on which the black king would be checkmate, in check, stalemate resp. safe.""" # Convert coordinate string 'a1', 'e4', etc. to (col,row), considering it # as a base 20 number to accommodate for digits 'a', 'b',... = 10, 11,... kc,kr = divmod(int( king ,20)-201, 20) # 'a' = digit 10 => col.0, ac,ar = divmod(int(amazon,20)-201, 20) # '1' = digit 1 => row 0. def forbidden(r,c): # Forbidden squares: at distance 1 from king. return abs(r-kr) < 2 and abs(c-kc) < 2 def shielded(r,c): # is the enemy king between r,c and ar,ac? # i.e., its coordinates (row & col) are between our's and amazon's # and we see the king and amazon in the same direction, i.e., # directional vectors (delta row, delta col) are collinear <=> # determinant is zero: return (kc-c)*(ar-r) == (kr-r)*(ac-c) and min(c,ac) <= kc <= max(c,ac)\ and min(r,ar) <= kr <= max(r,ar) def threatened(r,c): # is square (r,c) threatened by the amazon? # <=> row or column is equal [rook move] or on diagonal (bishop move: # absolute differences of row & col are equal) or we're not more than # 2 steps away (includes knight moves), and not shielded by king: return (r==ar or c==ac or abs(c-ac)==abs(r-ar) or (abs(r-ar) < 3 and abs(c-ac) < 3)) and not shielded(r,c) def can_move(r,c): # if black is at r,c, is there a safe square next to it? return any(not threatened(rr,cc) and not forbidden(rr,cc) for rr in range(max(r-1,0), min(r+2,8)) for cc in range(max(c-1,0), min(c+2,8), 2 if rr == r else 1)) cnt=[0]*4 for r in range(7): for c in range(7): if not forbidden(r,c): # 0, 1, 2, 3 <=> checkmate or check only, stalemate or safe cnt[ (0 if threatened(r,c) else 2) + can_move(r,c) ] += 1 return cnt ```