Question

In: Computer Science

In this project, you will be expanding on recent In-Class Activity to create a basic Scrabble...

In this project, you will be expanding on recent In-Class Activity to create a basic Scrabble Game. You do not need to worry about the game board, just the logic of the game. You may have up to 3 programmers in your group.

In this version of the game, players indicate how many rounds of play there will be for two players. Then each player will take turns entering words until the number of rounds are complete. In order for a word to be accepted, a letter in the word must correspond to a letter in a previous word. The exception is for the first word entered will be accepted without validating as there is nothing to validate against.

  1. On the inputRounds() method, validate the number entered is numeric. If it is not, return a default numeric value of 2 instead.
  2. On the inputWord() method, pass the player number and display in the input message.
  3. On the inputWord() method, call a validation method called validWord(). This method will check to make sure the current word entered has a letter contained from the previous round with the exception of the first word entered.
  4. On the validWord() method, the following validations need to take place:
    • Return False when word entered is empty
    • Return False when the word entered is the same as the previous word
    • Return True when nothing has been entered (ie this is the start of the game and as long as a word is not empty bypass validation)
    • Return False when the word entered must has no letters in common with the previous word entered
  5. In the main program create the following Lists, Dictionaries, and Tuples
    • Create a Variables for player information using the names: rounds, player1, score1, player2, score2
    • Utilize the provided function that returns a Dictionary for the points per letter called points
    • Utilize the provided function that returns a List for end of game messages called messages
  6. Optional unit testing available requires methods initMessages(), initPoints() to setup the initial values of the tuples, dictionaries and lists.

Values for messages List

Format Text Replacement will be used for the {} Text. See https://pyformat.info/ for more information on how to use the format() method.

  • Player {} Wins with a score of {}!
  • Tie Game, no winners.
  • Invalid word! Player {} Wins!
  • Invalid word! You must enter a valid word to start.
  • Player {} Entered the Words:

Point Values Per Letter for points Dictionary

  • 1 Point for Letters: a e i l n o r s t u
  • 2 Points for Letters: d g
  • 3 Points for Letters: b c m p
  • 4 Points for Letters: f h v w y
  • 5 Points for Letters: k
  • 8 Points for Letters: j x
  • 10 Points for Letters: q z

To use this call points['a'], where a is any lowercase letter you want to find the point value for.

Data Types for Variables

  • rounds:
  • currPlayer:
  • prevPlayer:
  • player1:
  • score1:
  • player2:
  • score2:

Rubric / Grading Scale

  • Appropriate Output of Instructions for user input for the number of rounds and words (6pt)
  • 2 Functions utilized for initializing default values of points and messages (4pt)
  • 4 Functions created as specified for inputRounds(), inputWord(), validWord(), playerScore() (12pt)
  • 3 Unit Test cases found on test_main.py pass with OK (9pt)
  • Working Scrabble Game per the above rules (19pt)

Total Points: 50

Additional Grading Notes

  • Programmers must have attention to detail, as a result up to 2 Points may be taken for not updating the student info (Name, CRN, Semester Year) in the Markdown and Python Comments.
  • Customers will not pay for programs that do not work, as a result up to 50 Points may be taken for programs that do not run due to syntax errors.
  • Programmers tend to forget how large programs work over time, as a result up to 4 Points may be taken for programs that do not have a reasonable amount of comments that describe key sections of code.
  • Minimum of 4 or more commits made to GitHub showing incremental programming changes towards the final program (4pt)
    • 1 Commit may be for updating Student Info in the Markdown and Python File
    • 3 Commits must be for programming updates to source code
    • If a unit test is available, no changes made to the Unit Test will count towards the required commits (nor should there be any changes made to this file).
    • This is a team project, all group members must have at least one commit with code changes. Updating student info does not count.
  • All programs must have your Github URL submitted in Canvas via the assignment page. Unsubmitted Github repos will receive 0 Points.
  • Programs that have been submitted and received a grade will not be regraded, unless the instructor makes a request for changes.
  • If a program is eligible for regrading, it is the responsibility of the student to inform the instructor when the program is ready for regrading.

Here is what i have so far... i need help

# Function 1: Input Player Rounds

def inputRounds():

try:

rounds = int(input("Please enter the number of rounds you would like to play: "))

except:

rounds = 2

print("Invalid response using default value of: ", rounds)

print(rounds)

return None

# Function 2: Input Player Word

def inputWord():

word = str(input("Please enter your word: "))

return(word)

# Function 3: Validate Word

def validWord():

return None

# Function 4: Generate Score

def playerScore():

return None

# Method 5: Initialize List with Messages

def initMessages():

messages = [

'Player {} Wins with a score of {}!',

'Tie Game, no winners.',

'Invalid word! Player {} Wins!',

'Invalid word! You must enter a valid word to start.',

'Player {} Entered the Words:'

]

return messages

# Function 6: Initialize Points Dictionary

def initPoints():

points = {

"a": 1 , "b": 3 , "c": 3 , "d": 2 ,

"e": 1 , "f": 4 , "g": 2 , "h": 4 ,

"i": 1 , "j": 8 , "k": 5 , "l": 1 ,

"m": 3 , "n": 1 , "o": 1 , "p": 3 ,

"q": 10, "r": 1 , "s": 1 , "t": 1 ,

"u": 1 , "v": 4 , "w": 4 , "x": 8 ,

"y": 4 , "z": 10

}

return points

# Main Program

if __name__ == '__main__':

# Initialize Player Variables

# Declare Variables

points = initPoints()

messages = initMessages()

# Start Game Below

inputRounds()

inputWord()

Solutions

Expert Solution

Here is the detailed solution code with comments :

# Function 1: Input Player Rounds
def inputRounds():
    try:
        rounds = int(input("Please enter the number of rounds you would like to play: "))
    except:
        rounds = 2
        print("Invalid response using default value of: ", rounds)
    return rounds

# Function 2: Input Player Word
def inputWord(player,prev_word):
    #take input from user
    word = str(input("Player:"+str(player)+", Please enter your word: "))
    s = 0
    #if player input a valid word, score will be calculated
    if(validWord(word,prev_word)):
        s = playerScore(word)
    #return the word and the score for this turn
    return(word,s)

# Function 3: Validate Word
def validWord(word,prev_word):
    #check for empty word
    if(prev_word==""):
        return True
    #compare current word with previous word
    elif(word=="" or word==prev_word):
        return False
    #if the AND operation of two sets give one or more characters, means they have common letters
    elif(len(list(set(word)&set(prev_word)))>0):
        return True
    else:
        return False


# Function 4: Generate Score
def playerScore(word):
    s = 0 
    for i in word:
        s+=points[i]
    return s

# Method 5: Initialize List with Messages
def initMessages():
    messages = [
    'Player {} Wins with a score of {}!',
    'Tie Game, no winners.',
    'Invalid word! Player {} Wins!',
    'Invalid word! You must enter a valid word to start.',
    'Player {} Entered the Words:'
    ]
    return messages

# Function 6: Initialize Points Dictionary
def initPoints():
    points = {
    "a": 1 , "b": 3 , "c": 3 , "d": 2 ,
    "e": 1 , "f": 4 , "g": 2 , "h": 4 ,
    "i": 1 , "j": 8 , "k": 5 , "l": 1 ,
    "m": 3 , "n": 1 , "o": 1 , "p": 3 ,
    "q": 10, "r": 1 , "s": 1 , "t": 1 ,
    "u": 1 , "v": 4 , "w": 4 , "x": 8 ,
    "y": 4 , "z": 10
    }

    return points

# Main Program
if __name__ == '__main__':
    #initialize global variables
    points = initPoints()
    messages = initMessages()
    
    #intializing variables
    player1 = 1
    player2 = 2
    total_score1 = 0 
    total_score2 = 0
    
    #input the number of rounds
    rounds = int(inputRounds())
    
    #inititalizing variables with empty string
    prev_word1 = ""
    prev_word2 = ""
    
    #for loop to repeat multiple times
    for i in range(0,rounds):
        #printing round number.
        print("Round:",i+1)
        
        #player1 turn
        prev_word1,score = inputWord(player1,prev_word1)
        total_score1+=score
        
        #player2 turn
        prev_word2,score = inputWord(player2,prev_word2)
        total_score2+=score
    
    #printing the total scores        
    print("Player 1 Score:",total_score1)
    print("Player 2 Score:",total_score2)
    
    #printing the winner with greater score
    if(total_score2>total_score1):
        print("Player 2 Won!!!!")
    elif(total_score2<total_score1):
        print("Player 1 Won!!!!")
    else:
        print("Draw!!!")

OUTPUT:

Hope it Helps!

Thumbsup ;}


Related Solutions

android studio -Starting with a basic activity, create a new Java class (use File->New->Java class) called...
android studio -Starting with a basic activity, create a new Java class (use File->New->Java class) called DataBaseManager as in Lecture 5 and create a database table in SQLite, called StudentInfo. The fields for the StudentInfo table include StudentID, FirstName, LastName, YearOfBirth and Gender. Include functions for adding a row to the table and for retrieving all rows, similar to that shown in lecture 5. No user interface is required for this question, t -Continuing from , follow the example in...
In this project, you will create a Visual Basic solution to perform customer billing at the...
In this project, you will create a Visual Basic solution to perform customer billing at the Cyberian Internet Cafe. Please see below for the detailed instructions. You will create the project and then design a form using the image provided here. Then, add the necessary code to do the billing calculation and display the amount due. Instructions In this case, you will create a Visual Basic solution that performs customer billing for the Cyberian Internet Café. The Cyberian Internet Café...
Visual Basic Your first job is to create a visual basic project that will display the...
Visual Basic Your first job is to create a visual basic project that will display the name and telephone number for the contact person for the customer relations, marketing, order processing, and shipping departments. Include a button for each department. When the user clicks on the button for a department the program(in code for specific button will display the name and telephone number for the contact person in two labels. The same two labels will be used for each department...
create a project and in it a class with a main. We will be using the...
create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?"); int w = scan.nextInt();...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
Create a new Java project called lab1 and a class named Lab1 Create a second class...
Create a new Java project called lab1 and a class named Lab1 Create a second class called VolumeCalculator. Add a static field named PI which = 1415 Add the following static methods: double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder. double static method named cube that receives 1 double parameter...
In this assignment you create a small project with a base class 'Account' which represents a...
In this assignment you create a small project with a base class 'Account' which represents a generic account independent of whether the account is a Client or Vendor or Bank account. Then we will define a derived class 'BankAccount' class that represents the bank account. The BankAccount class is derived from the Account class, and extends the Account class functionality. The functionality of the BankAccount class is to handle deposits and withdrawals. You create a base class called Account and...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama Write a static method in that class called makeLists that takes no parameters and returns no value In makeLists, create an ArrayList object called avengers that can hold String objects. Problem 2 Add the following names to the avengers list, one at a time: Chris, Robert, Scarlett, Clark, Jeremy, Gwyneth, Mark Print the avengers object. You will notice that the contents are displayed in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT