class CityMap extends o1.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
.
- Alphabetic
- By Inheritance
- CityMap
- Grid
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new CityMap(homesPerSide: Int, populations: Vector[(Demographic, Int)])
- 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
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def allElements: Vector[Demographic]
Returns a collection of all the elements currently in the grid.
Returns a collection of all the elements currently in the grid.
- Definition Classes
- Grid
- def allPositions: Vector[grid.GridPos]
Returns a collection of all the locations on the grid.
Returns a collection of all the locations on the grid.
- Definition Classes
- Grid
- def apply(location: grid.GridPos): Demographic
Returns the element at the given pair of coordinates.
Returns the element at the given pair of coordinates. (This does the same as
elementAt
.)- location
a location on the grid (must be within range)
- Definition Classes
- Grid
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def contains(location: grid.GridPos): Boolean
Determines whether the grid contains the given pair of coordinates.
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).
- Definition Classes
- Grid
- def elementAt(location: grid.GridPos): Demographic
Returns the element at the given pair of coordinates.
Returns the element at the given pair of coordinates. (This does the same as
apply
.)- location
a location on the grid (must be within range)
- Definition Classes
- Grid
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- val height: Int
- Definition Classes
- Grid
- def initialElements: Seq[Demographic]
Generates the elements that initially occupy the grid.
Generates the elements that initially occupy the grid. In the case of a
CityMap
grid, this means generating newDemographic
objects at random locations so that their distribution matches thepopulations
parameter of theCityMap
.- returns
a collection of size
width
timesheight
that contains the initial grid elements. The first element in the collection will appear atGridPos
(0,0), the second at (1,0), and so on, filling in the first row before continuing on the second row at (1,0).
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def matches(address: o1.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.- 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)
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def neighbors(middleLoc: grid.GridPos, includeDiagonals: Boolean): Vector[Demographic]
Returns a vector of all the neighboring elements of the indicated element.
Returns a vector of all the neighboring elements of the indicated element. Depending on the value of 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 that is at the edge of the grid 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.
- middleLoc
the location between the neighbors
- includeDiagonals
true
if diagonal neighbors also count (resulting in up to eight neighbors),false
if only cardinal directions count (resulting in up to four)
- Definition Classes
- Grid
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- val size: Int
the number of elements in this grid, in total.
the number of elements in this grid, in total. (Equals
width
timesheight
.)- Definition Classes
- Grid
- def swap(location1: grid.GridPos, location2: grid.GridPos): Unit
Swaps the elements at two given locations on the grid, which must be within range.
Swaps the elements at two given locations on the grid, which must be within range.
- Definition Classes
- Grid
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString: String
- Definition Classes
- AnyRef → Any
- def update(location: grid.GridPos, newElement: Demographic): 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.
- location
a location on the grid (must be within range)
- newElement
the new element that replaces the old one at
location
- Definition Classes
- Grid
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- val width: Int
- Definition Classes
- Grid
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated @deprecated
- Deprecated
(Since version ) see corresponding Javadoc for more information.