kt_solve_recursively: Find a knight's tour recursively

Description Usage Arguments Value Examples

View source: R/01_Knights_Tour.R

Description

Recursively search for a knight's tour on a NxN chess board. Currently returns no more than one solution. The knight begins on a corner square.

Usage

1
2
3
4
5
kt_solve_recursively(N = 8, position = c(i = 1, j = 1),
  moves = list(c(2, 1), c(1, 2), c(-1, 2), c(-2, 1), c(-2, -1), c(-1,
  -2), c(1, -2), c(2, -1)), solution = matrix(c(1, rep(NA_integer_, N^2 -
  1)), nrow = N), last_move = c(i = 0, j = 0),
  pb = txtProgressBar(style = 3))

Arguments

N

The size of the NxN chess board.

position

A numeric vector of length 2 describing the coordinates of the proposed next position on a chess board.

moves

List of numeric vectors describing the valid moves a kight can make in a game of chess.

solution

Numeric NxN matrix describing the (possibly partial) knight's tour.

last_move

Numeric vector of length 2 describing the last move in the (possibly partial) knight's tour.

pb

Text progress bar to view progress in constructing a knight's tour.

Value

A NxN matrix describing a knight's tour if a solution exists. Otherwise FALSE.

Examples

1

jsphdms/backtrack documentation built on May 29, 2019, 1:24 p.m.