| Title: | Board Games and Tools for Building Board Games |
|---|---|
| Description: | Tools for constructing board/grid based games, as well as readily available game(s) for your entertainment. |
| Authors: | Derek Qiu [aut, cre] |
| Maintainer: | Derek Qiu <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 1.0.0 |
| Built: | 2026-05-19 09:18:00 UTC |
| Source: | https://github.com/cran/BoardGames |
This function allows for the detection of a particular sequence in a matrix.
detect_seq(data, sequence, reps, diag = TRUE)detect_seq(data, sequence, reps, diag = TRUE)
data |
A matrix. |
sequence |
The desired sequence to search for. |
reps |
Number of repetitions of the sequence. |
diag |
Do you want to search diagonals? Defaults to TRUE. |
M = matrix(sample(c(1,2),25,replace=TRUE),5,5) detect_seq(data = M, sequence = "2", reps = 5) #or equivalently detect_seq(data = M, sequence = "22222", reps = 1)M = matrix(sample(c(1,2),25,replace=TRUE),5,5) detect_seq(data = M, sequence = "2", reps = 5) #or equivalently detect_seq(data = M, sequence = "22222", reps = 1)
This function extracts all column vectors of a matrix and returns the result as a list.
get_cols(data)get_cols(data)
data |
Matrix from which to extract column vectors. |
M = matrix(rnorm(9),3,3) get_cols(M)M = matrix(rnorm(9),3,3) get_cols(M)
This function extracts all diagonal vectors of a matrix and returns the result as a list.
get_diags(data, direction = "right")get_diags(data, direction = "right")
data |
Matrix from which to extract diagonal elements |
direction |
Which side to begin on? Takes values of one of "left", "right" or "both". Defaults to "right". |
M = matrix(rnorm(9),3,3) get_diags(M)M = matrix(rnorm(9),3,3) get_diags(M)
This function extracts all row vectors of a matrix and returns the result as a list.
get_rows(data)get_rows(data)
data |
Matrix from which to extract row vectors. |
M = matrix(rnorm(9),3,3) get_rows(M)M = matrix(rnorm(9),3,3) get_rows(M)
This function extracts all surrounding elements of a specified element in a matrix and returns the result as a vector.
get_surround(data, index, type = "all")get_surround(data, index, type = "all")
data |
Matrix. |
index |
Index position of element. Input as a vector of row then column positions. |
type |
Takes values of "direct" and "all". "direct" returns only the elements directly in contact with the specified element, whereas "all" returns every surrounding element including diagonals. Defaults to "all". |
M = matrix(1:20,4,5) get_surround(data = M, index = c(2,3))M = matrix(1:20,4,5) get_surround(data = M, index = c(2,3))
This function converts a matrix index into unit x,y plotting coordinates.
index2xy(data, index)index2xy(data, index)
data |
Matrix or data frame. |
index |
A vector of index values. |
M = matrix(1:20,4,5) index2xy(data = M, index = c(3,4))M = matrix(1:20,4,5) index2xy(data = M, index = c(3,4))
This function checks if the supplied vector is a palindrome (reads the same forwards and backwards).
is_palindrome(x, case.sensitive = FALSE)is_palindrome(x, case.sensitive = FALSE)
x |
Numeric or character vector. |
case.sensitive |
Does upper or lower casing matter? Defaults to FALSE. |
test1 = 123 test2 = "12321" test3 = c("a",1,2,3,2,1,"a") is_palindrome(test1) is_palindrome(test2) is_palindrome(test3)test1 = 123 test2 = "12321" test3 = c("a",1,2,3,2,1,"a") is_palindrome(test1) is_palindrome(test2) is_palindrome(test3)
This function allows one to play the Ultimate version of Tic-Tac-Toe. In the Regular version of Tic-Tac-Toe, players take turns placing their marks, with the objective of achieving three marks in a row in any direction. 9x9 Tic-Tac-Toe or more commonly known as Ultimate Tic-Tac-Toe, adds a twist on the regular version of Tic-Tac-Toe that most of us have come to know. Perceive the board as a big Tic-Tac-Toe board, with the goal being to achieve 3 big marks in any direction. Big marks are achieved by winning the corresponding small Tic-Tac-Toe blocks. The player to move first may play anywhere on the board. However, following moves must correspond to the same big Tic-Tac-Toe block of the small Tic-Tac-Toe board where the last move was played.
UltimateTicTacToe()UltimateTicTacToe()
This function converts a set of unit x,y coordinates into a matrix index.
xy2index(data, x, y)xy2index(data, x, y)
data |
Matrix or data frame. |
x |
x-coordinate |
y |
y-coordinate |
M = matrix(1:20,4,5) xy2index(data=M, x=3, y=2)M = matrix(1:20,4,5) xy2index(data=M, x=3, y=2)