This function allows swapping of cards within a row of a card matrix. It takes a card matrix and the indices of the columns to swap. The function modifies the card matrix in-place and returns the updated matrix.
swapper(cards_matrix, swap_in_row = NULL)
The updated card matrix with the specified cards swapped within a row.
A matrix of cards representing the current state of the game.
A vector of length 2 specifying the indices of the columns to
swap within a row. If NULL
(default), no swapping is performed.
The function performs the following steps:
Initializes a move history attribute if it doesn't exist.
Checks if swap_in_row
is provided and has a length of 2.
Verifies that swapping within a phase has not been performed more than once.
Swaps the cards at the specified column indices within the first row of the matrix.
Updates the move history attribute.
Adds the "swapper" class to the card matrix.