Alternatively: Now you're checking with portals!
I am somewhat of a self-declared Chess Anarchist. That means that when I play chess, en passant is forced (else the brick gets used), double check is mate (and pasta), and all sorts of new pieces and squares are added to the game.
One such piece is the Knook (also called an "Empress" or "Chancellor" in fairy chess). It moves like a horsey and a rook combined. Another common addition are portals, like the kinds you see in the Portal series. They behave as you would expect.
Therefore, in this challenge, I'll be give you the position of a white knook, two black kings and an orange and blue portal. You'll give me the square I should move my knook to in order to check both the kings at once and win the game.
Detailed Explanation of Knooks and Portals
The Knook
Here is how a knight moves in chess:
Here is how a rook moves in chess:
Therefore, this is how a knook (knight + rook) moves in chess:
In BCPS notation, it's move is EM
. In Parlett notation, it's move is n+, ~ 1/2
. In Betza notation, it's move is RN
.
Portals
From the Portal Wiki:
Portals in a pair act as a direct link between one another. Anything that goes into one portal comes instantly out the other.
Therefore, when a piece moves into a portal, it comes out the other portal. Portals occupy a single square. There are only ever two portals on a board - one orange and one blue. Pieces cannot land on a portal, as they'd just infinitely teleport between the orange and blue portals. Pieces can also attack through portals (so a piece in a position where another piece could exit a portal would be able to be taken.)
Here's are some examples of how a rook would move through a portal. Note that it always exits the other portal in the direction it entered the first portal. Note that the rook also cannot "jump" over the portal - it has to go through if there is a portal in its way.
Here's how a knight would move through portals. Note that it can either move two squares into a portal and exit one square in a perpendicular direction, or one square into a portal and exit two squares in a perpendicular direction.
Therefore, this is how a knook would move through a portal, obeying laws of both the rook and knight portal movement rules:
An Example
On the following board, the knook is on square b2
, the black kings are on d7
and f6
and the portals are on squares b5
and d2
. The winning move is to move the knook through the blue portal to d5, which checks the king on d7
via rook moves and the king on f6
via knight moves.
On the following board, the knook is on square c5
, the black kings are on g3
and h4
and the portals are on squares f7
and g4
. The winning move is to move the knook to d7
, as the knook threatens to take the king on h4
with rook moves after portal travel and threatens to take the king on g3
with knight moves after portal travel.
On the following board, the knook is on square f4
. The black kings are on b8
and d3
. The portals are on squares f6
and a4
. The winning move is to move the knook through the portal on d6
and exit the portal on a4
via a knight move (up 2, right 1). This checks both kings.
Rules
- The positions will be given in algebraic chess notation (letter then number of the square).
- The winning move will be returned in algebraic chess notation.
- Positions can be given and returned in any reasonable and convienient format, including:
- A list of strings (e.g.
["f4", "b8", "d3", "f6", "a4"]
) - A list of list of strings (e.g.
[["f", "4"], ["b", "8"], ["d", "3"], ["f", "6"], ["a", "4"]]
) - A list of list of numbers that represent the character codes of each string item (e.g.
[[102, 52], [98, 56], [100, 51], [102, 54], [97, 52]]
) - A list of string, number pairs (e.g.
[["f", 4], ["b", 8], ["d", 3], ["f", 6], ["a", 4]]
)
- A list of strings (e.g.
- Input formats and output formats don't have to match, so long as they are consistent.
- Piece positions can be taken in any order (e.g.
[portal 1, portal 2, knook, king 1, king 2]
or[knook, king 1, king 2, portal 1, portal 2]
) - This doesn't change much, but you can assume that the black kings will never be on the
c2
square. - You may assume that there will always be at least one solution to each input.
- The board layout may start with 0 or 1 king(s) already in check. Your goal is to double check.
- Double check is strictly defined as checking both kings for this challenge. A knook checking a king through a portal and starting in check is counted as a single check only for simplicity.
- It doesn't matter if a king can capture the knook if double check is achieved. All that matters is that both kings are in check at the same time.
- If there is more than one solution, you can output one, or all of the solutions.
- Portal travel might not be required for a winning move. Double check via normal knook movement is just as valid as portal usage.
- This is code-golf, so the shortest answer in bytes in each language wins.
Testcases
Input order is [knook, king 1, king 2, portal 1, portal 2]
Positions -> Winning Square
["b2", "d7", "f6", "b5", "d2"] -> "d5"
["c5", "g3", "h4", "f7", "g4"] -> "d7"
["f4", "b8", "d3", "f6", "a4"] -> "a4"
["h1", "a1", "a3", "c1", "f1"] -> "b1"
["c2", "a8", "h8", "d2", "d6"] -> "d8"
["d2", "c6", "g2", "b2", "g7"] -> "g6"
["d3", "f6", "h6", "d4", "e4"] -> "g4"
["c4", "f7", "h5", "a2", "f5"] -> "b2" // Attacks through the portal
["h5", "a7", "e2", "a4", "g6"] -> "g3" // Attacks a7 through the portal and e2 normally.
["h6", "d4", "g3", "a1", "a8"] -> "f5" // No portal travel needed