Viinaharava Docs
Fall 2026
API

# GameBoard

o1.viinaharava.GameBoard
class GameBoard(`width`: Int, `height`: Int, `boozeCount`: Int) extends Grid[Glass]

Each instance of the class `GameBoard` represents a board for a game of Viinaharava. A game board is a `Grid` whose elements are `Glass` objects.

A `GameBoard` is first initialized with water glasses (by initialElements). However, a number of the glasses are then immediately poured full of booze while the rest keep their default content of water.

Once created, a `GameBoard` does not replace any of its `Glass` objects with another. However, the state of each individual `Glass` may change.

## Parameters

boozeCount

  the number of booze glasses on the game board. When a `GameBoard` object is created, it randomly chooses this many different locations on the board and pours booze in them.

height

  the number of rows of glasses in the game board

width

  the number of glasses in each row of the game board

## Attributes

Graph
Supertypes
  trait Grid[Glass]
  class Object
  trait Matchable
  class Any

## Members list

### Value members

#### Concrete methods

def boozeGlasses: Seq[Glass]

Returns a collection of all the booze glasses currently on the board.

Returns a collection of all the booze glasses currently on the board.

## Attributes

def drink(`target`: Glass): Unit

Virtually drinks the contents of the given glass.

Virtually drinks the contents of the given glass.

For a glass of water, “drinking” it just means that the glass is emptied. (If the water glass was already empty, this method does nothing.)

For a glass of booze, “drinking” it empties not just that glass but also all the other glasses of booze on the game board. (This will have carry-on effects in the game’s GUI: all the locations of booze glasses will be revealed, and the game will end. However, this method does nothing more than empty the glasses.)

## Parameters

target

  a glass on this game board

## Attributes

def initialElements: Seq[Glass]

Generates the elements that initially occupy the grid. In the case of a `GameBoard` grid, this means generating a new `Glass` object for each location on the board. This method is automatically invoked by the superclass `Grid` to initialize the contents of the grid.

Generates the elements that initially occupy the grid. In the case of a `GameBoard` grid, this means generating a new `Glass` object for each location on the board. This method is automatically invoked by the superclass `Grid` to initialize the contents of the grid.

Note to students: You don’t need to call this method. Don’t call it. You might want to call `allElements`, though.

## Attributes

def isGameOver: Boolean

Determines whether the game is over. The game is over if (a) there are one or more empty booze glasses on the board; or (b) there are no full water glasses on the board.

Determines whether the game is over. The game is over if (a) there are one or more empty booze glasses on the board; or (b) there are no full water glasses on the board.

## Attributes

def isOutOfWater: Boolean

Determines whether all the water on the board has been drunk already. This is the case if and only if each of the glasses either contains booze or is empty.

Determines whether all the water on the board has been drunk already. This is the case if and only if each of the glasses either contains booze or is empty.

## Attributes

#### Inherited methods

def allElements: Vector[Glass]

Returns a collection of all the elements currently in the grid.

Returns a collection of all the elements currently in the grid.

## Attributes

Inherited from:
  Grid

def allPositions: Vector[GridPos]

Returns a collection of all the locations on the grid.

Returns a collection of all the locations on the grid.

## Attributes

Inherited from:
  Grid

def apply(location: GridPos): Glass

Returns the element at the given pair of coordinates. (This does the same as `elementAt`.)

Returns the element at the given pair of coordinates. (This does the same as `elementAt`.)

## Parameters

location

  a location on the grid (which must be within range or this method will fail with an error)

## Attributes

Inherited from:
  Grid

def contains(location: GridPos): Boolean

Determines whether the grid contains the given pair of coordinates. For instance, a grid with a width and height of 5 will contain (0, 0) and (4, 4) but not (-1, -1), (4, 5) or (5, 4).

Determines whether the grid contains the given pair of coordinates. For instance, a grid with a width and height of 5 will contain (0, 0) and (4, 4) but not (-1, -1), (4, 5) or (5, 4).

## Attributes

Inherited from:
  Grid

def elementAt(location: GridPos): Glass

Returns the element at the given pair of coordinates. (This does the same as `apply`.)

Returns the element at the given pair of coordinates. (This does the same as `apply`.)

## Parameters

location

  a location on the grid (which must be within range or this method will fail with an error)

## Attributes

Inherited from:
  Grid

def neighbors(middleLoc: GridPos, includeDiagonals: Boolean): Vector[Glass]

Returns a vector of all the neighboring elements of the element indicated by the first parameter. Depending on the second parameter, either only the four neighbors in cardinal compass directions (north, east, south, west) are considered, or the four diagonals as well.

Returns a vector of all the neighboring elements of the element indicated by the first parameter. Depending on the second parameter, either only the four neighbors in cardinal compass directions (north, east, south, west) are considered, or the four diagonals as well.

Note that an element at the grid’s edge has fewer neighbors than one in the middle. For instance, the element at (0, 0) of a 5-by-5 grid has only three neighbors, diagonals included.

## Parameters

includeDiagonals

  `true` if diagonal neighbors also count (resulting in up to eight neighbors), `false` if only cardinal directions count (resulting in up to four)

middleLoc

  the location between the neighbors

## Attributes

Inherited from:
  Grid

def randomElement(): Glass

Returns a random element from the grid. Uses the scala.util.Random singleton.

Returns a random element from the grid. Uses the scala.util.Random singleton.

## Attributes

Inherited from:
  Grid

def randomPos(): GridPos

Returns a random location from the grid. Uses the scala.util.Random singleton.

Returns a random location from the grid. Uses the scala.util.Random singleton.

## Attributes

Inherited from:
  Grid

def swap(location1: GridPos, location2: GridPos): Unit

Swaps the elements at two given locations on the grid. The given locations must be within range or this method will fail with an error.

Swaps the elements at two given locations on the grid. The given locations must be within range or this method will fail with an error.

## Attributes

Inherited from:
  Grid

def update(location: GridPos, newElement: Glass): Unit

Modifies the grid by replacing the existing element at the given location with the new element.

Modifies the grid by replacing the existing element at the given location with the new element.

## Parameters

location

  a location on the grid (which must be within range or this method will fail with an error)

newElement

  the new element that replaces the old one at `location`

## Attributes

Inherited from:
  Grid

#### Inherited fields

val size: Int

the number of elements in this grid, in total. (Equals `width` times `height`.)

the number of elements in this grid, in total. (Equals `width` times `height`.)

## Attributes

Inherited from:
  Grid