Question
Problem Description Objective This practical tests your skills of writing classes. It also requires planned application of logic and code structure. Problem In this practical
Problem Description
Objective
This practical tests your skills of writing classes. It also requires planned application of logic and code structure.
Problem
In this practical assignment, you are going to implement a simple Rock, Paper, Scissors game in C++. Two players compete and, independently, choose one of Rock, Paper, or Scissors. They then simultaneously declare their choices. The winner of the game is determined by comparing the choices of the players. Rock beats Scissors, Scissors beats Paper, Paper beats Rock.
Your implementation needs to adhere to an approved* abstraction and interface for the human player, referee and computer player. One possible abstraction and interface based on this abstraction is shown below. This is the one we discussed in this week's workshp:
A possible interface for my RPS game based on this abstraction.
HumanPlayer
HumanPlayer( ); // constructor char makeMove( );
ComputerPlayer
ComputerPlayer( ); // constructor char makeMove( );
Referee
Referee( ); // constructor char refGame(HumanPlayer player1, ComputerPlayer player2) // returns the outcome for player1: 'W', 'L' or 'D' (Win, Lose, Draw)
You can choose to implement this interface. Alternatively, you have created your own UMLs in workshop this week. If the public members of your UMLs have been approved* in your workshop, you can also implement that approved* interface.
*approved interfaces are the group designs agreed by your tutor during your workshop to improve on the default interface given here. I will add testing code for these approved interfaces to the web submission for practical 2. Approved interfaces must improve on the above abstraction/interface.
Your submission should contain
Human.cpp Human.h Computer.cpp Computer.h Referee.cpp Referee.h
The next practical assignment will build on this practical so you should make your code as extendable as possible. In Practical 3, we will consider more complex computer strategies.
Implementation Details
Computer Player
For this assignment, to make things simple, we assume that the computer player only plays Rock.
Human Player
The human players strategy is read from the input which consists of one single line. The line starts with a positive integer k, then followed by k moves (separated by spaces). A move is a character among R, P, and S.
For example, the input 3 S P R means that the human player will play scissors, then paper, and then rock. If asked to play more, the human will cycle back through the choices again: scissors, paper, rock. Note this way of setting the strategy by keyboard input is only done for testing purposes as we need to know what moves your human will be making in order to test your code works. If testing were not required, this information should be hidden within the player implementation.
Referee
The referee class will match two players and return their game result. For this practical, your referee class matches the human player and the dumb computer player (who only plays rock). In Practical 3, your referee class will need to match different computer players against each other.
The main
The main program will create the objects needed and then run some number of rock paper scissors games (up to the main function to decide how many).
Main will make the request to the referee object to referee the game. Main will print the returned result.
For example, if the main decides to play 4 games, and the human player (first player) strategy input is 3 S P R, the output should be L W T L (L = human loses; W = human wins; T = tie). Another example can be that for human strategy input 4 R R P S, the output should be T T W L. (recall the dump computer player always plays rock).
The main purpose of this practical is for you to practise organizing and writing classes and to recognise how your implementation of your classes can change without having to change the code in main.
Marking Scheme
Functionality (3 marks):
- Classes implement the interface - ie they will compile with a main that uses the given or other approved* classes (1 mark) Passing public test cases (1 mark) Passing hidden test cases (1 mark)
RPS : Abstraction human player computer player t make movel) make Move ( move e move i ref-game player I, plays 2) t referee result same controller responsible for setting up games and reporting results RPS : Abstraction human player computer player t make movel) make Move ( move e move i ref-game player I, plays 2) t referee result same controller responsible for setting up games and reporting resultsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started