COSC 3P91
Assignment 1

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


RoboRace (Part 1)

In the four assignments of this course you are going to implement a game called RoboRace. RoboRace is a robot race game in which each player attempts to be the first to reach a goal by manoeuvring a programmable robot across a factory hall. The factory hall itself is a dynamic race course with conveyor belts, pitfalls, presses and turning devices. In this assignment you are going to implement some basic classes and methods of the game.

The Game

RoboRace is played in rounds. Each player (1-4) controls a robot that has a location and a direction it is facing. Each robot starts at location (2x+1,0) with x between 1 and 4 facing north (start configuration). Each round consists of four phases:
  1. Initial phase
  2. Deal Program cards
  3. Plan Programs
  4. Execute Programs

Initial phase

All dead robots are revived. Such a robot has starting configuration.

Deal Program cards

In each turn each player gets randomly 7 program cards out of 84 from which (s)he has to select 5. Those cards will maneuver the robot. Every card has a priority number. This gives the order in which the players will move their robots, higher priority moves first. The 84 cards are:

Number / Priority
Name
Effect
1-18
Turn right
Turns the robot (changes the direction it is facing) to the right (clockwise).
19-36
Turn left
Turns the robot (changes the direction it is facing) to the left (counter clockwise).
37-42
Turn 180°
Turns the robot (changes the direction it is facing) by 180°.
43-48
Move backwards (1 step)
Moves the robot 1 location backwards (does not change the direction it is facing).
49-66
Move (1 step)
Moves the robot 1 location forwards (does not change the direction it is facing).
67-78
Move (2 steps)
Moves the robot 2 locations forwards (does not change the direction it is facing).
79-84
Move (3 steps)
Moves the robot 3 locations forwards (does not change the direction it is facing).

Plan Programs

Using the cards dealt in the beginning of the round each player must make a program of exactly 5 cards. This program will control the Robot. Each player picks 5 cards in the order in which they are supposed to be executed.

Execute Program

When the players are executing their programs, the robots will be moved through the commands of the chosen program cards and they will be influenced by the factory elements. The execution of the programs is done in five execution steps (according to the five program cards). In each execution step the following will happen:
  1. One card of each player is executed in order of their priority.
  2. Activate factory elements at the position of each robot.

There can only be one robot in each square. A robot that moves into a space occupied by another robot cannot move through or jump over that robot. Instead it will push that robot forward without regard to the orientation of the pushed robot. Both movements occur simultaneously.

When a robot tries to cross a side of square with a wall it will be blocked and the robot will stay in the space without completing that command. This applies to both forwards and backwards movement. Notice, that a robot that is pushed and blocked by a wall will also block the pushing robot.

When a robot falls into a pit or moves outside the board it will be destroyed. This effect takes places immediately. Robots cannot, in no circumstances, cross pits.

After a program card is executed for each robot the robots will be influenced by the factory elements. A robot will only be influenced by the elements present in the space it occupies. This occurs just once each execution step, i.e., a movement due to a factory element to a new space does not cause another effect by the new factory element. Here the only exception is a pit (see above). There are two kinds of factory elements, decorations (Pusher and Crusher) and tiles (Conveyer Belt, Floor, Gear, Goal, Pit). Each space has a tile and might have a decoration. The effect of a decoration is always executed first. The effects of the elements are as follows:

  1. Pushers push robots during the indicated execution steps into the neighboring space.
  2. Crushers destroy robots during the indicated execution steps.
  3. Conveyor belts transport robots 1 space in the indicated direction.
  4. Floors do not have any effect.
  5. Gears rotate robots 90° in the indicated direction.
  6. Goals end the game. The robot on that spot is the winner of the game.
  7. Pits destroy robots.
When a robot is moved by a factory element it might be blocked by walls or it may push other robots as described above.

The program

The design of the program is described by the following class diagrams. In this first assignment you have to implement the following:
  1. The method execute in all subclasses of Card.
  2. The method step in the class Board.
  3. The method effect in the class Location.
  4. The method effect in all classes implementing Tile.
  5. The method effect in all classes implementing Decoration.
  6. The class Player. Use the method CardList selectCards(CardList list) of the CardPane class in order to let the player select the cards.
  7. The class GameMaster.

In the execute method of a card you should implement its effect on the robot. For each individual action you have to create an event and to add it to the EventList parameter. The EventList will be used later starting from Assignment 2 when the GameMaster and each Player work on different copies of the Board/Factory. Simultaneous events (pushing) must have the same EventCounter, i.e. the step values as well as the action values are equal. Actions that are related to one card use an EventCounter with the same action value. The events are described in the following table:

Class
Explanation
BumpEvent
A robot hitting a wall.
MoveEvent
A one step movement as part of executing a card or be pushed by another robot.
DestoyedEvent
A robot is destroyed by either moving from the board, falling into a pit or be crushed by a crusher.
TurnEvent
The robot turns clockwise or counter-clockwise. This can also be caused by a program card or a gear.
HalfturnEvent
The robot does a 180° turn.
VictoryEvent
The robot is at the goal.

The step method should be called in order to execute a move card. A call of step results in a one step movement of a robot on the board. This method should take care of pushing, falling of the board and/or into a pit.

An object of the GameMaster class will actually run the game. Implement the main loop of the game in the method run.

Packages, sources, etc.:
COSC Home Page
COSC 3P91 Home Page
© M. Winter, 2017