R/random_mover.R

Defines functions random_mover

Documented in random_mover

#' @title random_mover
#'
#' @description engine which chooses randomly between legal moves
#'
#' @param game chess game object (i.e., a list with elements board, turn, history, and fen_history
#'              as created by newgame function)
#'
#' @return game with new move done
#' @export
#'

random_mover <- function(game) {
  chosenone <- sample(legalmoves(game), 1)

  message("Chosen move by random mover:")
  message(chosenone)

  chess_move(game,
             piece = substr(chosenone, 1, 1),
             initialposition =  substr(chosenone, 2, 3),
             finalposition =  substr(chosenone, 4, 5))
}

Try the chess2plyrs package in your browser

Any scripts or data that you put into this service are public.

chess2plyrs documentation built on June 8, 2025, 10:03 a.m.