COSC 3P91

Assignment 2

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


RoboRace (Part 2)

In this assignment you are going to use XML and multiple threads. The communication between the threads will use the Producer-Consumer design pattern.

Multiple Threads

The instances of the class Player and the main class GameMaster are supposed to use different threads within your application. Furthermore, those classes are not supposed to share any information, e.g., a link to the same board in the Player and GameMaster class is not allowed. Any information has to be send through a channel (see design pattern Producer Consumer) as XML code.

Create the diffrent threads in the method main, i.e., move the creation of the players from the GameMaster class to the method main (if not already done).

Design Pattern Producer-Consumer

The communication between the main class and the players should use the Producer-Consumer design pattern. Any information, i.e., the initial board, the list of cards, the selected cards and the list of events, has to be transmitted using this design pattern. You have to extend/modify the design pattern to allow a two-way communication. You have to provide your own implementation, i.e., you are not allowed to use the classes PipedInput/OutputStream, Vector or any other synchronized/thread-safe implementation of a pipe or list. You may use a LinkedList or ArrayList, of course.

Classes EventListReader and EventReader

Implement these classes as XMLReaders of the appropriate type. You will find XML schema files specifying the syntax of the XML code in the XSD folder.
In addition, implement the method

public void execute(Board board)

in each event class in order to execute the sequence of GameEvents on a board. This should be used by the Player class to update its copy of the board according to execution of the cards in the class GameMaster. Notice that you don't have to do any kind of checks during the execution since this was already done by the GameMaster.

Messages

The following information is transmitted during the game. At start-up the initial board is sent to Player. In each iteration the GameMaster sends the cards, receives the selected cards, and sends the EventList. No further board object is transmitted.

Remarks


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