class RobotWorld extends o1.Grid[Square]
An instance of the class RobotWorld
represents a mutable, two-dimensional world
that can be inhabited by virtual robots. This kind of "robot world" is a Grid
whose elements are Square
objects.
Robots -- RobotBody
objects -- can be added to the robot world, and the robot
world object maintains a listing of the added robots. It uses this list to have
the robots take their turns in a round-robin fashion.
Apart from robots, a robot world can also contain walls. All robot worlds are bounded by walls on all sides: all the edge squares of all robot worlds are always unpassable by robots. Wall squares may also be added at other locations within a robot world.
- See also
- Alphabetic
- By Inheritance
- RobotWorld
- Grid
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new RobotWorld(floorWidth: Int, floorHeight: Int)
- floorWidth
the width of the robot world, in squares, in addition to the walls on both sides. The total width of the grid will be two plus this number.
- floorHeight
the height of the robot world, in squares, in addition to the walls at the top and at the bottom. The total height of the grid will be two plus this number.
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 addRobot(initialLocation: o1.GridPos, initialFacing: o1.CompassDir): RobotBody
Creates a new robot into this robot world.
Creates a new robot into this robot world. The newly created robot body does not yet have a brain.
This method is responsible for several related things: creating the robot (body), adding the robot to the list of robots in this world (so it will get a turn to act), and informing the robot's initial square that the robot is now there (by calling the square's
addRobot
method).- initialLocation
the initial location of the new robot in this world. This method assumes that
location
points to an empty square.- initialFacing
the direction that the robot is initially facing in
- returns
the newly created robot body, which has been placed in the indicated square
- def addWall(location: o1.GridPos): Unit
Marks a square in this robot world as being an unpassable wall square.
Marks a square in this robot world as being an unpassable wall square. This method assumes that the location of the wall, given as a parameter, points to an empty square.
- def advanceFullRound(): Unit
Causes all the robots in the world to take a turn, starting with the one whose turn it is next.
Causes all the robots in the world to take a turn, starting with the one whose turn it is next. (After this is done, the robot who originally was next up, will be that once again.)
- def advanceTurn(): Unit
Causes the next robot to take a turn.
Causes the next robot to take a turn. The turn then immediately passes to the next robot.
- See also
- def allElements: Vector[Square]
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): Square
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): Square
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: IndexedSeq[Square]
Generates the elements that initially occupy the grid.
Generates the elements that initially occupy the grid. In the case of a
RobotWorld
grid, an element is aSquare
object --- either a Floor instance or the Wall singleton. Initially, all the edge squares of the robot world are walls and the inner squares are emptyFloor
squares. This method is automatically invoked by the superclassGrid
to initialize the contents of the grid.- returns
a collection that contains the initial grid elements. The first element will appear at
GridPos
(0,0), the second at (1,0), and so on, filling in the first row before continuing on the second row at (0,1).
- Definition Classes
- RobotWorld → Grid
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def neighbors(middleLoc: grid.GridPos, includeDiagonals: Boolean): Vector[Square]
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
- def nextRobot: Option[RobotBody]
Returns the robot whose turn it is to act.
Returns the robot whose turn it is to act. That is, returns the robot who will be the next one to act when advanceTurn or advanceFullRound is called.
The robots take turns in a round-robin fashion: the first one to act is the first one that was added, the second to act is the second one to be added, and so on. When the robot that was added last has taken its turn, it becomes the first one's turn again.
Note that calling this method does not actually cause any robots to act or change the state of the robot world in any way. The method merely returns the robot whose turn it is.
(Clarifications: If a robot is added to the world while the last robot in the "queue" has the turn, it is perfectly possible for the new robot to get its first turn very soon, as soon as the previously added robot has acted. A newly added robot never immediately gains the turn, however, unless it is the first one to be added and therefore the only robot in the whole world.)
- returns
the robot whose turn it is next, wrapped in an
Option
;None
if there are no robots in this world
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def numberOfRobots: Int
Returns the number of robots (robot bodies) that have been added to this world.
- def robotList: Vector[RobotBody]
Returns a collection of all the robots in this robot world, in the order they were added to the world.
- 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: Square): 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.