CityMap

o1.city.CityMap
class CityMap(homesPerSide: Int, populations: Vector[(Demographic, Int)]) extends Grid[Demographic]

A CityMap is a square grid that represents a simplified map of a city. It is a Grid whose elements are Demographic objects. That is, each GridPos (“street address”) on a CityMap is either Vacant or stores a household that belongs to aparticular demographic.

A CityMap is mutable. As a household moves, the corresponding Demographic object moves to a different GridPos on the CityMap.

Parameters

homesPerSide

the number of street addresses in each row and each column of the city grid (which is always square)

populations

a vector of pairs in which each Demographic is matched with a count of how many times it appears on this city map

Attributes

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

Members list

Value members

Concrete methods

Generates the elements that initially occupy the grid. In the case of a CityMap grid, this means generating new Demographic objects at random locations so that their distribution matches the populations parameter of the CityMap.

Generates the elements that initially occupy the grid. In the case of a CityMap grid, this means generating new Demographic objects at random locations so that their distribution matches the populations parameter of the CityMap.

Attributes

def matches(address: GridPos, householdType: Demographic): Boolean

Determines whether the household at the given “street address” (GridPos) belongs to the given demographic.

Determines whether the household at the given “street address” (GridPos) belongs to the given demographic.

Parameters

address

a location on the city grid to examine

householdType

a demographic that the household at the given address is compared to (may be Vacant, too, in which case this method checks if the address is vacant)

Attributes

Inherited methods

def allElements: Vector[Element]

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

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): Element

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

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): Element

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

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

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

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

Concrete fields

Returns all the locations in the city.

Returns all the locations in the city.

Attributes

Inherited fields

val height: Int

Attributes

Inherited from:
Grid
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
val width: Int

Attributes

Inherited from:
Grid