Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First - Pawn Brotherhood solution in Clear category for Pawn Brotherhood by AQiccl135
FILES = "abcdefgh"
def safe_pawns(pawns):
# Start with zero safe pawns, then check each pawn
safe = 0
for each in pawns:
# This really should say "> 2", but some of the pawns have moved back a
# rank
if int(each[1]) > 1:
# Checks if any of the positions that can protect a pawn are occupied
if any(every in pawns for every in get_protectors(each[0], int(each[1]))):
safe += 1
return safe
def get_protectors(file, rank):
file_index = FILES.index(file)
row_below = str(rank - 1)
# Gets both protectors if the pawn is not on the edge of the board ...
if file in FILES[1:-1]:
protectors = [FILES[file_index - 1] + row_below, FILES[file_index + 1] + row_below]
# ... or the only protector if the pawn is on an edge
elif file == 'a':
protectors = ['b' + row_below]
else:
protectors = ['g' + row_below]
return protectors
Oct. 31, 2014
Comments: