BATTLECRY - Battle Of The Bastards - Kings Vs Rooks
In this problem, we’ll be considering a slightly modified version of chess with the following rules:
- The game will be played on a N x N board.
- The game will consist of exactly 4 pieces - The white king, the black king, and two white rooks. All four pieces must be placed on different squares of the board.
- Kings can move to any adjacent square (horizontally, vertically, or diagonally), unless the square is outside the board or occupied by a friendly piece or if the move would place the king under check.
- Rooks can move to any square in the same rank or file, but not by jumping over other pieces. Also it cannot land on a square occupied by a friendly piece.
- A piece X is threatened by another enemy piece Y, iff Y can reach X in exactly one legal move.
- A piece X can capture another enemy piece Y iff X can reach Y in exactly one legal move. On capturing, piece Y is removed from the board and X takes its place. Note that if X is the king, then it cannot capture Y if Y is guarded by an enemy piece. That is the king can never move and put itself in danger where it is attacked by an enemy piece.
- The two kings cannot ever be in adjacent (horizontally, vertically or diagonally) squares.
- The objective of the game is to place the four pieces on unique squares of the board in such a way that if it is black’s move, then the black king is attacked and has no legal moves. That is, the black king must be threatened by at least one of the white rooks and has no way to move to a safe square or eliminate the checks (by capturing the attacking pieces if not guarded). Note that it is not necessary for the board configuration to be legal following the exact rules of chess. That is, if N = 8 there might be valid configurations in our modified game which might never appear in a game of chess. Like the figure shown below, which can never occur in a proper game of chess given that it is black’s turn to move, although it would be a perfectly valid configuration in our game.
Given N, you need to count how many ways you can place one white king, one black king, and two white rooks in the chessboard such that the black king is threatened and has no way to escape the threat given it is black’s turn to move. Two configurations are different if either any of the squares contain different pieces or one square contains a piece but the other does not. Note that every square is uniquely represented by it’s rank and file and hence mirrored or reversed configurations of the same configuration will be considered as different configurations. Also note that the white king, black king and white rooks are distinguishable but the two white rooks are identical. So in the figure above, if we swap the two rooks, the new configuration will be the same as the old one.
Since the number of ways can be huge, you need to output it modulo 7340033.
InputThe first line contains the number of test cases denoted by T. The next T lines contain the board dimension N.
OutputFor each case, output one line. First output the case number then the number of valid ways modulo 7340033. Please refer to the sample i/o for more clarity on the format.
8 1 2 3 4 5 6 7 8
Case 1: 0 Case 2: 0 Case 3: 232 Case 4: 1432 Case 5: 5188 Case 6: 14536 Case 7: 34464 Case 8: 72392
ExplanationFor a 8 x 8 board, here are some valid configurations:
For all of these boards, the black king is attacked and has nowhere to go. Also both the white rooks are placed in the board and the kings are not in adjacent positions.
And here are some invalid ones:
For the first board, the black king can move and capture the attacking white rook thereby removing the check and moving to a safe square. For the second board, although the black king is attacked and cannot capture anything because all the pieces are guarded, the two kings are adjacent which is not allowed. Hence it is not a valid checkmate position. For the third board, it is stalemate. That is the black king has nowhere to go but it is also not attacked. So no checkmate. For the fourth board, it is checkmate and the black king has nowhere to go. But we haven’t placed both the rooks in the board and hence this is not a valid position.
It didn't take long for link rot to break the embedded images.