swapper: Swap Cards Within a Row of a Card Matrix

View source: R/napjack_helpers.R

swapperR Documentation

Swap Cards Within a Row of a Card Matrix

Description

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.

Usage

swapper(cards_matrix, swap_in_row = NULL)

Arguments

cards_matrix

A matrix of cards representing the current state of the game.

swap_in_row

A vector of length 2 specifying the indices of the columns to swap within a row. If NULL (default), no swapping is performed.

Details

The function performs the following steps:

  1. Initializes a move history attribute if it doesn't exist.

  2. Checks if swap_in_row is provided and has a length of 2.

  3. Verifies that swapping within a phase has not been performed more than once.

  4. Swaps the cards at the specified column indices within the first row of the matrix.

  5. Updates the move history attribute.

  6. Adds the "swapper" class to the card matrix.

Value

The updated card matrix with the specified cards swapped within a row.

Note

The function modifies the card matrix in-place and returns the updated matrix.


scdtb documentation built on Sept. 30, 2024, 9:35 a.m.