Starting from:

$25

PSP0101 -Problem Solving and Program Design - ASSIGNMENT - Solved

Battle of the Sexes (B.O.T.S) 

Introduction
 

Tony and Pepper is a married couple. Due to their heavy commitment at work, they have not been dating for quite some time. They decided to do something different for their next date. Unfortunately, they could not make up their mind. Tony was looking forward to watch Copa America’s final football match with Pepper, while Pepper wanted Tony to join her for the live concert of Super Junior boy band. Both the match and live concert were held on the same day, and both Tony and Pepper did not want to forgo their preferences.

 

Morgan, a 5-year-old programming genius and the daughter of Tony and Pepper, loves her parents very much. She figured that the best way to resolve her parents’ differences was to let them play a fair game, the winner of which gets to decide the plan for the date. Although Morgan could have used any existing board games for this purpose, she thought that it is more fun to design a new game and program it to run on a computer. She called her new game as “Battle of the Sexes”, or B.O.T.S in short.

Mission
 

You are to develop the game “Battle of the Sexes” using Python programming language based on Problem Description and Program Requirements below.


 

Starter Kit
 

You should find a folder named Starter Kit in the same folder as this document. This folder contains files that help you kick start your assignment. Here are the files in the folder:

 

1. psphelper.py 
 

This Python source code contains some helpful functions that you can use in your program. Check out the documentation of each function to know what they do. You do not have to modify this file at all.

 

2. Tutorial.py 
 

This Python source code demonstrates how to use the functions in psphelper.py. Run it to see how the functions in psphelper.py are used.  

 

3. game.exe_rename 
 

This is actually an executable for the game. It is given for your reference. To run it, kindly rename it to game.exe, open command prompt at the executable’s location, and type game.

 

 

             

Problem Description
 

Here are the general descriptions about the game to be developed for this assignment.

(1)   Battle of the Sexes is a two-player turn-based game in which players competes for the highest score by rolling dice to make certain combinations.

(2)   There are Five (5) dice to roll. Each die is a tetrahedron (i.e. a triangular pyramid with 4 faces) and therefore has Four (4) values only: 1, 2, 3 and 4.

(3)   The game begins with each player having a total score of 0.

(4)   The game consists of 9 rounds. In each round, the players take turns to roll dice. Each player can roll the dice up to three (3) times, but they can choose to accept the dice and stop rolling before the third roll. After the first or second roll, the player can re-roll some or all dice.

(5)   There are 9 scoring categories with which the dice are matched. After the third roll or after the player accepts the dice, the player has to choose which scoring category the dice is to be used. The player can only use a scoring category once.

(6)   Each scoring category has its own matching condition and scoring rule. Some of the matching conditions accept any dice combination, while others are specific to certain dice combinations. Some of the scoring rules are fixed scores, while others depend on the dice’s values. The table below illustrates all scoring categories in B.O.T.S.  

Category 
Matching Condition 
Scoring Rule 
Example 
Ones (1S) 
Any combination 
Sum of dice with number 1 
   Score = 3 
Twos (2S) 
Any combination 
Sum of dice with number 2 
   Score = 0 
Threes (3S) 
Any combination 
Sum of dice with number 3 
   Score = 6 
Fours (4S) 
Any combination 
Sum of dice with number 4 
   Score = 4 
Trio 
At least three dice the same 
Sum of ALL dice 
   Score = 8 

   Score = 0 (do not match) 
Quartet 
At least four dice the same 
Sum of ALL dice 
   Score = 0 (do not match) 

   Score = 14 
Doremi 
Four sequential dice (1-2-3-4) 
20 
   Score = 0 (do not match) 

  Score = 20 
Band 
Three of one number and two of the other 
30 
  Score = 30 

   Score = 0 (do not match) 
Orchestra 
All five dice the same 
40 
   Score = 40 
  

(7)   The scores obtained from the chosen scoring category will be accumulated into the player’s total score.  

(8)   After completing all rounds, the game ends and both players’ total scores are compared. The player who has the highest score wins.

Program Requirements
 

Here are the requirements that your program must satisfy to get FULL marks. You should read this while running game.exe for better understanding.

(A) Interface and Appearance 
 

1) First Interface 

The First Interface is the user interface that is always displayed first at each player’s turn. It contains several parts: Game Title, Scoreboard, Player’s Total, Current Player, and Roll-Dice Prompt. The example below illustrates each part clearly.  

 

 

(a)   Game Title: The game title is centre-justified on a width of 80 characters. 

(b)   Scoreboard: This part shows the players’ scores for each scoring category that has been used.

(c)   Player’s Total: This part shows the total scores the player has accumulated.

(d)   Roll Dice Prompt: This part instructs the current player to roll the dice to begin playing.   

 (B) Program Logic 
  

(1) The game begins with Player 1 starts first. At the beginning of each turn, the command prompt screen is cleared before the First Interface is displayed, causing the First Interface to be displayed at the top of the screen. 

[HINTS: Check out Tutorial.py for help on how to clear screen and display the Scoreboard.]

 

======================== Battle of the Sexes (B.O.T.S) ======================== Scoreboard 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

|          | 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 1 |    |    |    |    |      |         |      |        |           | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 2 |    |    |    |    |      |         |      |        |           | +----------+----+----+----+----+------+---------+------+--------+-----------+ 

 

Player 1: 0 

Player 2: 0 

 

Player 1 

======== Press ENTER to roll dice. 
 

(2) The player is asked to press the Enter key for the first roll. After the Enter key is pressed, the game will show “Roll #1” to indicate that this is the first roll, and will show a list of 5 random integers, each indicating the value of each die. This integer list is referred to as dice combination. Following the dice combination is a table titled “Category Scores”, which shows the scores the dice combination would contribute for each scoring category (refer to Problem Description for how the scores are calculated).  

 

======================== Battle of the Sexes (B.O.T.S) ======================== Scoreboard 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

|          | 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 1 |    |    |    |    |      |         |      |        |           | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 2 |    |    |    |    |      |         |      |        |           | +----------+----+----+----+----+------+---------+------+--------+-----------+ 

 

Player 1: 0 

Player 2: 0 

 

Player 1 

======== 

Press ENTER to roll dice. 

 
Roll #1 : [1, 2, 3, 1, 2] 

 

Category Scores 

+----+----+----+----+------+---------+------+--------+-----------+ 

| 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----+----+----+----+------+---------+------+--------+-----------+ 

|  2 |  4 |  3 |  0 |    0 |       0 |    0 |      0 |         0 | 

+----+----+----+----+------+---------+------+--------+-----------+ 
 

(3)   The Category Stores table is followed by Input Options, which shows the commands that the player can perform. The player can accept the dice combination, re-roll all 5 dice, or re-roll just the dice specified by a space-separated list of dice ordering number. An input prompt follows Input Options, waiting for the player to enter a command.

 

======================== Battle of the Sexes (B.O.T.S) ======================== Scoreboard 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

|          | 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 1 |    |    |    |    |      |         |      |        |           | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 2 |    |    |    |    |      |         |      |        |           | +----------+----+----+----+----+------+---------+------+--------+-----------+ 

 

Player 1: 0 

Player 2: 0 

 

Player 1 

======== 

Press ENTER to roll dice.  

Roll #1 : [1, 2, 3, 1, 2] 

 

Category Scores 

+----+----+----+----+------+---------+------+--------+-----------+ 

| 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----+----+----+----+------+---------+------+--------+-----------+ 

|  2 |  4 |  3 |  0 |    0 |       0 |    0 |      0 |         0 | +----+----+----+----+------+---------+------+--------+-----------+  

Input Options: 

  SAVE           :- Accept these dice.   ROLL           :- Re-roll ALL dice. 

  ROLL d1 ... dn :- Re-roll specified dice only.  Input > 
 

(4)   To accept the dice combination, the player must type “SAVE” in any letter casing (i.e. inputs like “SAVE”, “save”, “sAvE” are valid, as long as the word “save” is typed). The game will proceed to the selection of scoring category for the accepted dice combination as detailed in (8).

 

======================== Battle of the Sexes (B.O.T.S) ======================== Scoreboard 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

|          | 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 1 |    |    |    |    |      |         |      |        |           | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 2 |    |    |    |    |      |         |      |        |           | +----------+----+----+----+----+------+---------+------+--------+-----------+ 

 

Player 1: 0 

Player 2: 0 

 

Player 1 

======== 

Press ENTER to roll dice.  

Roll #1 : [1, 2, 3, 1, 2] 

 

Category Scores 

+----+----+----+----+------+---------+------+--------+-----------+ 

| 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----+----+----+----+------+---------+------+--------+-----------+ 

|  2 |  4 |  3 |  0 |    0 |       0 |    0 |      0 |         0 | +----+----+----+----+------+---------+------+--------+-----------+  

Input Options: 

  SAVE           :- Accept these dice.   ROLL           :- Re-roll ALL dice. 

  ROLL d1 ... dn :- Re-roll specified dice only.  

Input > sAVE 

Enter your desired category: 
 

(5)   To re-roll all dice, the player must type “ROLL” in any letter casing (i.e. inputs like “ROLL”, “roll”, “RolL” are valid, as long as the word “roll” is typed). The game will roll the dice again, showing the dice combination and its corresponding Category Scores similar to Program Logic (2) and (3). However, this time the roll number is either 2 (the second roll), or 3 (the third roll).

 

======================== Battle of the Sexes (B.O.T.S) ======================== Scoreboard 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

|          | 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 1 |    |    |    |    |      |         |      |        |           | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 2 |    |    |    |    |      |         |      |        |           | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 
 

Player 1: 0 

Player 2: 0 

 

Player 1 

======== 

Press ENTER to roll dice.  

Roll #1 : [1, 2, 3, 1, 2] 

 

Category Scores 

+----+----+----+----+------+---------+------+--------+-----------+ 

| 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----+----+----+----+------+---------+------+--------+-----------+ 

|  2 |  4 |  3 |  0 |    0 |       0 |    0 |      0 |         0 | +----+----+----+----+------+---------+------+--------+-----------+  

Input Options: 

  SAVE           :- Accept these dice.   ROLL           :- Re-roll ALL dice. 

  ROLL d1 ... dn :- Re-roll specified dice only. 

 

Input > Roll 

 

Roll #2 : [3, 1, 3, 1, 1] 

 

Category Scores 

+----+----+----+----+------+---------+------+--------+-----------+ 

| 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----+----+----+----+------+---------+------+--------+-----------+ 

|  3 |  0 |  6 |  0 |    9 |       0 |   25 |      0 |         0 | +----+----+----+----+------+---------+------+--------+-----------+  

Input Options: 

  SAVE           :- Accept these dice.   ROLL           :- Re-roll ALL dice. 

  ROLL d1 ... dn :- Re-roll specified dice only.  Input > 
 

(6)   To re-roll some dice, the player must type “ROLL   …   ”, where   to   are   space-separated list of positive integers corresponding to which die or dice to roll (e.g. “ROLL 1 3” means roll the 1st and the 3rd die). Similar to (5), the word “ROLL” is caseinsensitive. However, the order of   to   need not be sorted (i.e. “ROLL 1 3” should work the same as “ROLL 3 1”), and duplicates are allowed in the integer list (e.g. “ROLL 1 3 1 1 3” should work the same as “ROLL 1 3”). The output upon executing this command is similar to (5).

 

======================== Battle of the Sexes (B.O.T.S) ======================== Scoreboard 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 
|          | 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 1 |    |    |    |    |      |         |      |        |           | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 2 |    |    |    |    |      |         |      |        |           | +----------+----+----+----+----+------+---------+------+--------+-----------+ 

 

Player 1: 0 

Player 2: 0 

 

Player 1 

======== 

Press ENTER to roll dice.  

Roll #1 : [4, 4, 2, 4, 4] 

 

Category Scores 

+----+----+----+----+------+---------+------+--------+-----------+ 

| 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----+----+----+----+------+---------+------+--------+-----------+ 

|  0 |  2 |  0 | 16 |   18 |      18 |    0 |      0 |         0 | +----+----+----+----+------+---------+------+--------+-----------+  

Input Options: 

  SAVE           :- Accept these dice.   ROLL           :- Re-roll ALL dice. 

  ROLL d1 ... dn :- Re-roll specified dice only. 

 

Input > roll 2 1 5 4 1 

 

Roll #2 : [1, 2, 2, 3, 2] 

 

Category Scores 

+----+----+----+----+------+---------+------+--------+-----------+ 

| 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----+----+----+----+------+---------+------+--------+-----------+ 

|  1 |  6 |  3 |  0 |   10 |       0 |    0 |      0 |         0 | +----+----+----+----+------+---------+------+--------+-----------+  

Input Options: 

  SAVE           :- Accept these dice.   ROLL           :- Re-roll ALL dice. 

  ROLL d1 ... dn :- Re-roll specified dice only. 

 

Input > 
 

(7)   Apart from the SAVE and ROLL commands, the game also secretly supports the cheat command to overwrite the dice to a desired combination. The cheat command syntax is “CHEAT   …  ”. Here,   to   is a space-separated list of 5 positive integers that each represents the face value of a die (this is unlike the command for re-rolling some dice). The word “CHEAT” is case-insensitive, but there must be exactly 5 positive integers for the integer list. Since each die has only 4 values, the condition   must be true.

 

The cheat command can only be used once per turn, so no other commands are allowed after executing the cheat command. Upon executing the cheat command, the game will show the Category Scores corresponding to the entered dice, and proceed to the selection of scoring category (see (8)).

 

======================== Battle of the Sexes (B.O.T.S) ======================== Scoreboard 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

|          | 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 1 |    |  8 |    |    |      |         |      |        |           | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 2 |    |    |    |    |      |         |      |     20 |           | +----------+----+----+----+----+------+---------+------+--------+-----------+ 

 

Player 1: 8 

Player 2: 20 

 

Player 1 

======== 

Press ENTER to roll dice.  

Roll #1 : [1, 3, 2, 2, 2] 

 

Category Scores 

+----+----+----+----+------+---------+------+--------+-----------+ 

| 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----+----+----+----+------+---------+------+--------+-----------+ 

|  1 |  6 |  3 |  0 |   10 |       0 |    0 |      0 |         0 | +----+----+----+----+------+---------+------+--------+-----------+  

Input Options: 

  SAVE           :- Accept these dice.   ROLL           :- Re-roll ALL dice. 

  ROLL d1 ... dn :- Re-roll specified dice only. 

 

Input > cheat 1 1 1 1 0 

ERROR: Invalid input. 

Input > cheat 1 1 -1 1 1 

ERROR: Invalid input. 

Input > cheat 1 1 1 1 ERROR: Invalid input. 

Input > cheat 1 a 1 1 1 

ERROR: Invalid input. 

Input > cheat 1 1 1 1 1 

Category Scores 

+----+----+----+----+------+---------+------+--------+-----------+ 

| 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----+----+----+----+------+---------+------+--------+-----------+ 

|  5 |  0 |  0 |  0 |    5 |       5 |    0 |      0 |        40 | 
+----+----+----+----+------+---------+------+--------+-----------+  

Enter your desired category: 
 

(8)   The player has up to three (3) rolls per turn. Once the player has finalized the dice (i.e. has accepted the dice, rolled three times, or used the cheat command), the player is asked to enter the name of his desired scoring category for his finalized dice (as seen in the Category Scores table). If the entered scoring category has previously used, the game will report an error and ask the player to enter again.

 

Once the scoring category is entered, the player’s turn ends. His scoreboard will be updated with the new score obtained from the chosen scoring category, and his total score will be updated accordingly. After this, the next player’s turn begins.

 

======================== Battle of the Sexes (B.O.T.S) ======================== Scoreboard 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

|          | 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 1 |    |  8 |    |    |      |         |      |        |        40 | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 2 |    |    |    |    |      |         |      |     20 |           | +----------+----+----+----+----+------+---------+------+--------+-----------+ 

 

Player 1: 48 

Player 2: 20 

 

Player 2 

======== 

Press ENTER to roll dice.  

Roll #1 : [1, 4, 2, 4, 4] 

 

Category Scores 

+----+----+----+----+------+---------+------+--------+-----------+ 

| 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----+----+----+----+------+---------+------+--------+-----------+ 

|  1 |  2 |  0 | 12 |   15 |       0 |    0 |      0 |         0 | +----+----+----+----+------+---------+------+--------+-----------+  

Input Options: 

  SAVE           :- Accept these dice.   ROLL           :- Re-roll ALL dice. 

  ROLL d1 ... dn :- Re-roll specified dice only. 

 

Input > save 

Enter your desired category: doremi ERROR: Category 'doremi' has been used. 

Enter your desired category: tri 

ERROR: Category 'ban' does not exist. 

Enter your desired category: trio 
======================== Battle of the Sexes (B.O.T.S) ======================== Scoreboard 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

|          | 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 1 |    |  8 |    |    |      |         |      |        |        40 | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 2 |    |    |    |    |   15 |         |      |     20 |           | +----------+----+----+----+----+------+---------+------+--------+-----------+ 

 

Player 1: 48 

Player 2: 35 

 

Player 1 

======== 

Press ENTER to roll dice. 
 

(9)   The game continues to run for 9 rounds, with the screen of the command prompt cleared upon turn exchanges. After 9 rounds, the game ends, showing the Game Title, Scoreboard, and Players’ Total. The winner is determined by the player with the highest total score. If both players have the same score, it is considered a tie.  

 

======================== Battle of the Sexes (B.O.T.S) ======================== Scoreboard 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

|          | 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 1 |  2 |  6 |  6 |  4 |    0 |       0 |   25 |      0 |         0 | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 2 |  0 |  6 |  3 |  4 |   15 |       0 |    0 |      0 |         0 | +----------+----+----+----+----+------+---------+------+--------+-----------+ 

 

Player 1: 43  

Player 2: 28 

 

Player 1 wins! 
======================== Battle of the Sexes (B.O.T.S) ======================== Scoreboard 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

|          | 1S | 2S | 3S | 4S | Trio | Quartet | Band | Doremi | Orchestra | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 1 |  0 |  6 |  3 |  4 |   15 |       0 |   25 |      0 |         0 | 

+----------+----+----+----+----+------+---------+------+--------+-----------+ 

| Player 2 |  0 |  6 |  3 |  4 |   15 |       0 |   25 |      0 |         0 | +----------+----+----+----+----+------+---------+------+--------+-----------+ 

 

Player 1: 28  

Player 2: 28 

 

It’s a tie

More products