Berserk Rook Berserk Rook
English ES RU

As you may know, chess is an ancient game for which almost everyone has at least a basic understanding of the rules. Chess is a two-player strategy game played on a checkered game board laid out in eight rows (called ranks and denoted with numbers 1 to 8) and eight columns (called files and denoted with letters a to h) of squares. Each square of the chessboard is identified by a unique coordinate pair — a letter and a number (ex, "a1", "h8", "d6").

For this mission let's look at rooks, a dangerous shock unit which can be used for a swift thrust or for a dense defence. The rook moves horizontally or vertically, through any number of unoccupied squares, but may not leap over other pieces. As with capturing using any other unit, the rook captures by occupying the square on which the target enemy piece sits.

For this mission you have one berserk rook facing off against an army of enemy rooks. The berserk rook can only move if it will capture an enemy unit. So on each turn it will move and capture until there are no enemy targets left where it will take one "empty" step and stop.

You are given the position of your berserk rook and the positions of the enemy rooks. Your goal is capture as many units as possible without stopping. Each move in your sequence should capture an enemy unit. The result will be the maximum possible number of enemy rooks captured.


Input: Two arguments. Berserk rook position as a string and enemy rook positions as a set of strings.

Output: The maximum possible number of captured enemy rooks as an integer.


berserk_rook(u'd3', {u'd6', u'b6', u'c8', u'g4', u'b8', u'g6'}) == 5
berserk_rook(u'a2', {u'f6', u'f2', u'a6', u'f8', u'h8', u'h6'}) == 6
berserk_rook(u'a2', {u'f6', u'f8', u'f2', u'a6', u'h6'}) == 4

How it is used: For chess and any almost any other game it's important to think several steps forward. Here we have created a simple situation illustrating this concept. The basic idea is to think about optimisation problems using models.

0 < enemies ≤ 8