o1.grid

package o1.grid

Type members

Classlikes

enum CompassDir(val xStep: Int, val yStep: Int)

The type CompassDir represents the cardinal compass directions in a grid-like coordinate system. There are exactly four instances of this type: North, East, South and West, which are also defined in this package.

The type CompassDir represents the cardinal compass directions in a grid-like coordinate system. There are exactly four instances of this type: North, East, South and West, which are also defined in this package.

All the CompassDir objects are immutable.

This type and its instances have aliases in the top-level package o1, so they are accessible to students simply via import o1.*.

Value parameters:
xStep

the change in x coordinate if one moves one step in this direction. For instance, West has an xStep of -1 and North has an xStep of 0.

yStep

the change in y coordinate if one moves one step in this direction. For instance, North has an yStep of -1 and West has an yStep of 0.

See also:
Companion:
object
object CompassDir

This companion object of type CompassDir provides a selection of related constants and utility methods.

This companion object of type CompassDir provides a selection of related constants and utility methods.

This object has an alias in the top-level package o1, so it’s accessible to students simply via import o1.*.

Companion:
class
trait Grid[Element](val width: Int, val height: Int)

The trait Grid represents rectangular grids that contain elements of a particular kind. Each element in a grid is located at a unique pair of coordinates, represented as a GridPos.

The trait Grid represents rectangular grids that contain elements of a particular kind. Each element in a grid is located at a unique pair of coordinates, represented as a GridPos.

X coordinates run from 0 to width-1, y coordinates from 0 to height-1. (0,0) corresponds to the upper left corner of the grid.

There are different kinds of grids: the type of element that a grid contains is defined by the grid’s type parameter. For instance, Grid[Square] is a grid where each pair of x and y coordinates contains a Square object, and Grid[House] is a grid containing House objects.

A Grid is mutable: it is possible to replace an element at a particular GridPos with another. (Depending on the element type, the elements may be individually mutable, too.) The width and height of a grid never change, however.

Upon creation, a Grid initializes itself by calling initialElements, which produces an initial state for the grid.

This trait has an alias in the top-level package o1, so it’s accessible to students simply via import o1.*.

Value parameters:
height

the number of elements in each column of the grid

width

the number of elements in each row of the grid

final case class GridPos(x: Int, y: Int)

An object of type GridPos represents a pair of integer coordinates. Such a pair can be used to reference a point on a Grid.

An object of type GridPos represents a pair of integer coordinates. Such a pair can be used to reference a point on a Grid.

The coordinate axes are named x and y. In this coordinate system, x increases “eastwards” and y` increases “southwards”.

GridPos objects are immutable.

This class has an alias in the top-level package o1, so it’s accessible to students simply via import o1.*.

Value parameters:
x

an x coordinate

y

a y coordinate