Viinaharava Docs
Fall 2025
API

# o1.grid

package o1.grid

## Members list

### 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.*`.

## 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.

## Attributes

See also

  GridPos

Companion
  object
Supertypes
  trait Enum
  trait Serializable
  trait Product
  trait Equals
  class Object
  trait Matchable
  class Any
  Show all

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.*`.

## Attributes

Companion
  enum
Supertypes
  trait Sum
  trait Mirror
  class Object
  trait Matchable
  class Any
Self type
  CompassDir.type

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.*`.

## Parameters

height

  the number of elements in each column of the grid

width

  the number of elements in each row of the grid

## Attributes

Supertypes
  class Object
  trait Matchable
  class Any
Known subtypes
  class GameBoard

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.*`.

## Parameters

x

  an x coordinate

y

  a y coordinate

## Attributes

Companion
  object
Supertypes
  trait Serializable
  trait Product
  trait Equals
  class Object
  trait Matchable
  class Any
  Show all

object GridPos

This companion object of class `GridPos` provides a couple of utility methods.

This companion object of class `GridPos` provides a couple of utility methods.

## Attributes

Companion
  class
Supertypes
  trait Product
  trait Mirror
  class Object
  trait Matchable
  class Any
Self type
  GridPos.type