Submarine: Model the position of a submarine

SubmarineR Documentation

Model the position of a submarine

Description

Model the position of a submarine

Model the position of a submarine

Public fields

position

horizontal position

depth

vertical depth

Methods

Public methods


Method forward()

Move forward

Usage
Submarine$forward(x = 1)
Arguments
x

forward distance to add


Method down()

Move down

Usage
Submarine$down(x = 1)
Arguments
x

depth to add


Method up()

Move up

Usage
Submarine$up(x = 1)
Arguments
x

depth to subtraxt


Method move()

Move based on a set of commands

Usage
Submarine$move(commands)
Arguments
commands

vector of commands such as "forward 1", "down 2"


Method clone()

The objects of this class are cloneable with this method.

Usage
Submarine$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

dat <- "forward 5
down 5
forward 8
up 3
down 8
forward 2"
x <- strsplit(dat, "\n")[[1]]
s <- Submarine$new()
s$move(x)

karawoo/adventofcode2021 documentation built on Dec. 15, 2024, 9:06 a.m.