Packages

c

o1.robots

RobotWorld

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

Square

Linear Supertypes
grid.Grid[Square], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. RobotWorld
  2. Grid
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. 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

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. 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

  5. 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.

  6. 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.)

    See also

    nextRobot

    advanceTurn

    RobotBody.takeTurn

  7. 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

    nextRobot

    RobotBody.takeTurn

  8. 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
  9. 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
  10. 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
  11. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  12. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  13. 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
  14. 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
  15. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  17. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  18. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  19. val height: Int
    Definition Classes
    Grid
  20. 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 a Square 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 empty Floor squares. This method is automatically invoked by the superclass Grid 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
    RobotWorldGrid
  21. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  22. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. 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
  24. 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

  25. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  26. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  27. def numberOfRobots: Int

    Returns the number of robots (robot bodies) that have been added to this world.

  28. def robotList: Vector[RobotBody]

    Returns a collection of all the robots in this robot world, in the order they were added to the world.

  29. val size: Int

    the number of elements in this grid, in total.

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

    Definition Classes
    Grid
  30. 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
  31. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  32. def toString: String
    Definition Classes
    AnyRef → Any
  33. 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
  34. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  35. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  36. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  37. val width: Int
    Definition Classes
    Grid

Deprecated Value Members

  1. 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.

Inherited from grid.Grid[Square]

Inherited from AnyRef

Inherited from Any

Ungrouped