Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Berserk Rook by StanislauL
def berserk_rook(b, enemies):
res = 0
tmp = []
l1 = list(filter(lambda x: b[1]==x[1] and b[0]>x[0], enemies))
r1 = list(filter(lambda x: b[1]==x[1] and b[0] x[1], enemies))
d1 = list(filter(lambda x: b[0] == x[0] and b[1] < x[1], enemies))
l2,r2,u2,d2 = ((max,0),(min,0),(max,1),(min,1))
for x,y in (l1,l2),(r1,r2),(u1,u2),(d1,d2):
if x:
tmp.append(y[0](x, key = lambda z: z[y[1]]))
for x in tmp:
tmp_res = 1 + berserk_rook(x, enemies - {x})
res = tmp_res if tmp_res>res else res
return res
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert berserk_rook('d3', {'d6', 'b6', 'c8', 'g4', 'b8', 'g6'}) == 5, "one path"
assert berserk_rook('a2', {'f6', 'f2', 'a6', 'f8', 'h8', 'h6'}) == 6, "several paths"
assert berserk_rook('a2', {'f6', 'f8', 'f2', 'a6', 'h6'}) == 4, "Don't jump through"
Oct. 27, 2020