Robots Docs
Fall 2026
API

# GridPos

o1.grid.GridPos
See the GridPos companion object
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.

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
Graph
Supertypes
  trait Serializable
  trait Product
  trait Equals
  class Object
  trait Matchable
  class Any
  Show all

## Members list

### Value members

#### Concrete methods

def !=(another: GridPos): Boolean

Determines whether this grid position equals the given one. This is the case if and only if the two have identical x and y coordinates.

Determines whether this grid position equals the given one. This is the case if and only if the two have identical x and y coordinates.

## Attributes

def ==(another: GridPos): Boolean

Determines whether this grid position equals the given one. This is the case if and only if the two have identical x and y coordinates.

Determines whether this grid position equals the given one. This is the case if and only if the two have identical x and y coordinates.

## Attributes

def diff(another: GridPos): (Int, Int)

Returns the xDiff and yDiff between this `GridPos` and the given one as a pair.

Returns the xDiff and yDiff between this `GridPos` and the given one as a pair.

## Attributes

def distance(another: GridPos): Int

Returns the “grid distance” between this `GridPos` and the given one. The grid distance between `a` and `b` equals `a.xDiff(b).abs + a.yDiff(b).abs`.

Returns the “grid distance” between this `GridPos` and the given one. The grid distance between `a` and `b` equals `a.xDiff(b).abs + a.yDiff(b).abs`.

## Attributes

def neighbor(direction: CompassDir): GridPos

Returns a grid position that “neighbors” this one in the given direction. For instance, if this position has an `x` of 10 and a `y` of 20, and the `direction` parameter is given the value `CompassDir.South`, then the result has an `x` of 10 and a `y` of 21. Calling this method is essentially the same as calling `relative` with a `distance` of one.

Returns a grid position that “neighbors” this one in the given direction. For instance, if this position has an `x` of 10 and a `y` of 20, and the `direction` parameter is given the value `CompassDir.South`, then the result has an `x` of 10 and a `y` of 21. Calling this method is essentially the same as calling `relative` with a `distance` of one.

## Attributes

def pathTowards(direction: CompassDir): LazyList[GridPos]

Returns an infinite lazy-list of locations at increasing distances from this `GridPos` in the given direction. For example, if this `GridPos` is (10,1), and the direction is `South`, returns a list of (10,2), (10,3), (10,4), etc.

Returns an infinite lazy-list of locations at increasing distances from this `GridPos` in the given direction. For example, if this `GridPos` is (10,1), and the direction is `South`, returns a list of (10,2), (10,3), (10,4), etc.

## Attributes

def relative(direction: CompassDir, distance: Int): GridPos

Returns another grid position that is in the given direction from this one and at a given distance.

Returns another grid position that is in the given direction from this one and at a given distance.

For instance, say this position has an `x` of 10 and a `y` of 20. If `direction` is `CompassDir.North` and `distance` is 3, then the result has an `x` of 10 and a `y` of 17.

## Attributes

See also

  CompassDir.xStep, CompassDir.yStep

override def toString: String

Returns a textual description of this position. The description is of the form `"(x,y)"`.

Returns a textual description of this position. The description is of the form `"(x,y)"`.

## Attributes

Definition Classes
  Any

def xDiff(another: GridPos): Int

Returns the difference between the `x` coordinate of this `GridPos` and that of the given `GridPos`. The result is negative if the `x` coordinate of this `GridPos` is greater.

Returns the difference between the `x` coordinate of this `GridPos` and that of the given `GridPos`. The result is negative if the `x` coordinate of this `GridPos` is greater.

## Attributes

def xDirectionOf(another: GridPos): Option[CompassDir]

Determines if the given `GridPos` is west or east of this one. Returns `East` if this `GridPos`’s `x` coordinate is less than `another`’s and `West` if the opposite is true. Wraps that return value in an `Option`; `None` means that the `x` coordinates are equal.

Determines if the given `GridPos` is west or east of this one. Returns `East` if this `GridPos`’s `x` coordinate is less than `another`’s and `West` if the opposite is true. Wraps that return value in an `Option`; `None` means that the `x` coordinates are equal.

## Attributes

def yDiff(another: GridPos): Int

Returns the difference between the `y` coordinate of this `GridPos` and that of the given `GridPos`. The result is negative if the `y` coordinate of this `GridPos` is greater.

Returns the difference between the `y` coordinate of this `GridPos` and that of the given `GridPos`. The result is negative if the `y` coordinate of this `GridPos` is greater.

## Attributes

def yDirectionOf(another: GridPos): Option[CompassDir]

Determines if the given `GridPos` is north or south of this one. Returns `South` if this `GridPos`’s `y` coordinate is less than `another`’s and `North` if the opposite is true. Wraps that direction in an `Option`; `None` means that the `y` coordinates are equal.

Determines if the given `GridPos` is north or south of this one. Returns `South` if this `GridPos`’s `y` coordinate is less than `another`’s and `North` if the opposite is true. Wraps that direction in an `Option`; `None` means that the `y` coordinates are equal.

## Attributes

#### Inherited methods

def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

## Attributes

Inherited from:
  Product

def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

## Attributes

Returns

  in the default implementation, an `Iterator[Any]`

Inherited from:
  Product