Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Berserk Rook by IgorD
def berserk_rook(berserker, enemies):
rangev = 'abcdefgh'.split(berserker[0])
rangeh = '12345678'.split(berserker[1])
cnt = [0]
for i, sec in enumerate((reversed(rangev[0]), rangev[1], reversed(rangeh[0]), rangeh[1])):
for x in sec:
b = x + berserker[1] if i < 2 else berserker[0] + x
if b in enemies:
alive = enemies.difference(set((b,)))
cnt.append(1 + berserk_rook(b, alive))
break
return max(cnt)
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. 22, 2014
Comments: