Number of Valid Move Combinations On Chessboard

There is an 8 x 8 chessboard with n pieces, each a rook, a bishop, or a queen. You are given a string array pieces of length n, where pieces[i] is the type of the i-th piece, and a 2D integer array positions of length n, where positions[i] = [ri, ci] is the 1-indexed square (row ri, column ci) where the i-th piece currently sits. No two pieces start on the same square, and there is at most one queen on the board.

You must make one move for every piece at the same time. To move a piece, you choose a destination square that lies along one of that piece's legal rays, and the piece travels toward the destination and stops there.

  • A rook travels horizontally or vertically, toward (r+1, c), (r-1, c), (r, c+1), or (r, c-1).
  • A bishop travels diagonally, toward (r+1, c+1), (r+1, c-1), (r-1, c+1), or (r-1, c-1).
  • A queen travels along any of the eight directions listed above.

You may also choose the square a piece is already on as its destination, which means the piece stays put.

All pieces start moving at second 0. Every second, each piece instantly travels exactly one square toward its destination, unless it is already there, in which case it stays. A piece that has reached its destination keeps occupying that square at every later second.

A move combination is the set of moves chosen for all pieces. It is invalid if at any integer second two or more pieces occupy the same square. When two pieces are directly adjacent, it is valid for them to move past each other and swap squares in one second, because they are never on the same square at the same integer second.

Return the number of distinct valid move combinations. The pieces are distinguishable by their index, so choosing different destinations for different pieces counts as different combinations.

Examples
Input: [["rook"],[[1,1]]]
Output: 15
Hints

Number of Valid Move Combinations On Chessboard

There is an 8 x 8 chessboard with n pieces, each a rook, a bishop, or a queen. You are given a string array `pieces` of length n, where `pieces[i]` is the type of the i-th piece, and a 2D integer array `positions` of length n, where `positions[i] = [ri, ci]` is the 1-indexed square (row ri, column ci) where the i-th piece currently sits. No two pieces start on the same square, and there is at most one queen on the board.