COSC 3P91
Assignment 2

Instructor: Michael Winter, Office J323, email: mwinter@brocku.ca


RoboRace (Part 2)

The second assignment focuses on the execution of cards and effects by the GameMaster.

Methods step and stepRecursive

The methods step and stepRecursive of the Board class (package roborace.server) are used to move a robot one step into an adjacent space on the board. These methods should take care of pushing, falling of the board and/or into a pit. As a side effect the methods record what has happened in the parameter events so that each player can later update their visual representation of the game. The methods should do the following:
  1. Method step: This method will call stepRecursive appropriately and collect all events generated in the list events. Concretely, it should do the following:
    1. Create an empty event list called destroyedEvents.
    2. Call stepRecursive with the three parameters given and the empty list destroyedEvents.
    3. Add a EventWait to events.
    4. If the list destroyedEvents is not empty, then add all of its elements to the list events and then add an additional EventWait.
  2. Method stepRecursive: This method will actually move the robot(s) and generate corresponding events. All destroyed events should be added to the list destroyedEvents and all other events to the list events. Concretely, it should do the following:
    1. If the factory hall has a wall in the direction the robot needs to move (method hasWall), then create a EventBump, add it to the event list.
    2. Otherwise, compute the position to which the robot should be moved as a new Point. If the new position is off board or a pit, then move the robot into new position (use setPosition), kill the robot, create a EventStep and a EventDestroyed and add them to the corresponding list.
    3. Otherwise, check if the new position is occupied by a robot (use the private method robotIDAt, it returns the playerID of the robot at the position or -1 if there is no robot). If not, move the robot into the new position, create a EventStep and add it to the event list.
    4. Otherwise, call stepRecursive recursively for the robot in the new position. After the recursive call check if the new position is now free of robots. If so, then move the robot into the new position, create a EventStep and add it to the event list. Otherwise, create a EventBump and add it to the event list.

Method execute in all subclasses of Card

Implement the execute methods in all subclasses of Card (package roborace.server not roborace.client). These methods are used for executing program cards. In all implementations make sure that you execute any action on a robot only if it is still alive. Note, that a Move 3 card will actually execute up to 3 individual step actions. In each execute method (if the robot is alive) you should first add a EventCardStart to the event list, then execute the action as outlined below, and finally add a EventCardEnd to the event list.
  1. CardBack: Call step with a direction opposite to the direction the robot is facing (method rotate180 of the class Direction).
  2. CardMove: Call step with a direction the robot is facing as many times as indicated by the card.
  3. CardTurn180: Turn the robot (method turn180) and add a EventTurn180 to the event list.
  4. CardTurn90: Turn the robot (method turn90) and add a EventTurn90 to the event list.

Method effect in the class Factory

The method effect in the class Factory is supposed to execute the effect of a space on a robot. Note, that a decoration (if present) goes first, and the tile effect is only executed if there is no decoration or the decoration had no effect. Concretely, do the following:
  1. Use a temporary EventList in order to collect the effects of the decoration or tile.
  2. Call the effect of the decoration if it is present using the temporary event list (use the method getDecorationAt, it returns a decoration or null if there is none).
  3. If the decoration had no effect or the space has no decoration (temporary list is empty), then call the effect of the tile.
  4. If any effect was generated after the previous steps (temporary list is not empty), then add a EventEffectStart to the event list, add all events from the temporary list to the event list, and finally add a EventEffectEnd to the event list. In order to create a EventEffectStart you need to know whether the decoration or the tile produced the effect (parameter isDecorationEffect of the constructor of EventEffectStart).

Method effect in all subclasses Tile

Implement the effect method in all subclasses Tile as described below:
  1. TileBelt: Use the method step to move the robot in the indicated direction.
  2. TileFloor: No effect.
  3. TileGear: Turn the robot and add a corresponding event to the event list.
  4. TileGoal: Add a EventVictory to the event list.
  5. TilePit: No effect (this was already handled in the method step).

Method effect in all subclasses Decoration

Implement the effect method in all subclasses Decoration as described below:
  1. DecorationCrusher: If the current phase (parameter phase) is one of the 2 phases of the crusher, then destroy the robot and add a EventDestroyed to the event list.
  2. DecorationPusher: If the current phase (parameter phase) is one of the 3 phases of the pusher, then move the robot using step.

Sources


COSC Home Page
COSC 3P91 Home Page
© M. Winter, 2023