[Solved] Number-Guessing Game (Computer as Guessing Role)

$25

File Name: Number-Guessing_Game_(Computer_as_Guessing_Role).zip
File Size: 452.16 KB

SKU: [Solved] Number-Guessing Game (Computer as Guessing Role) Category: Tag:
5/5 - (1 vote)

OVERVIEW

In this assignment, you are going to design and develop an interactive number-guessing game. One participant (as host) is asked to pick a fixed length number (as secret number) and another participant (as game-player) is to guess the chosen number repeatedly. In the beginning of each game, a secret number is first picked by the host with no repeated digits, then repeatedly prompt the game-player for a guess of the secret number, without repeated digits. In return after each guess, the game-player will be given some feedbacks about the guess. Based on the feedback, the game-player continues to guess until the secret number is correctly guessed or the maximum number of attempts is reached.

The feedback provided to the game-player by the host contains 2 pieces of information as follows:

  1. How many of the digits in the guess also appear in the secret number (as Correct)
  2. How many of the digits from Correct appear in the same position as secret numbers (as Exact)

For instances, say the chosen secret number is 2468, the following table shows the feedback as a result of each guess provided by the game-player:

Guess Correct Exact Remark
1357 0 0 None of the digits (1,3,5 & 7) are from 2468
2890 2 1 Only digits 2 & 8 appear in 2468 and digit 2 is in the exact position
8294 3 0 Only digits 2, 4 & 8 appear in 2468 and none of 3 digits appear in the exact position
2486 4 2 All digits from guess also from 2468 and only digits 2 & 4 appear in the exact position
2468 4 4 Guess matches secret number

You are asked to design and develop a program to be the guessing role. In other words, the computer program as game player makes the guess and you as host provides the computer program with the feedback interactively.

SCOPE

  1. You are free to implement your program for 3-digit or 4-digit guessing, in python.
  2. In the beginning of each game, indicate to the host the number of digits your program is designed to guess.
  3. Inform the host to choose a secret number with no repeated digits and have it written down somewhere.
  4. Prompt host to start the game
  5. Your program as game-player starts to guess, after each guess, prompt host for feedback as described in the Overview session:
    1. How many correct digits?
    2. How many exact digits? (skip this question if Correct is 0)
  6. Your program is required to verify the responses returned by the host. If needed, repeatedly prompt host to re-enter the correct information, such examples as:
    1. Non-numeric responses
    2. Value of Exact is greater than that of Correct
    3. Value of either Correct or Exact should be less than the length of the secret number

(3 or 4)

  1. Inconsistent responses
  1. Feedback History
    1. Keep a list of history of all guesses including corresponding feedback, and then display the entire list after each guess in chronological order
  2. Termination
    1. the current guess matches the secret number
    2. In this case, display a congratulation message
    3. the number of guess attempts reaches the limit
    4. Display a game-over message
    5. the host enters x on any of the 2 feedback (Correct or Exact)
  3. Termination Prompt
    1. After termination, prompt host to quit or to continue a new game.
  4. Game Startup
    1. Show a welcome message to briefly describe what your program does
    2. Then prompt host for the secret number prior to starting the game
  5. For 3-digit number implementation, your program MJST successfully guessed the secret number within 20 attempts.
  6. For 4-digit number implementation, your program MJST successfully guessed the secret number within 40 attempts.

TARTUP OPTIONS

Not applicable

SKILLS

In this assignment, you will be trained on the use of the followings:

  • Use input() to prompt user for information
  • Use standard objects (strings, numbers & lists)
  • Control statements to interact with users
  • Variable Scope
  • String formatting (method style)
  • Functions for program structure and decomposition

DELIVERABLES

  1. Design documentation (A1_School_StudentID_Design.doc)
  2. Program source code (A1_School_StudentID_Source.py)
  3. Output (A1_School_StudentID_Output.doc)

Zip all files above in a single file (A1_School_StudentID.zip) and submit the zip file by due date to the corresponding assignment folder under Assignment (submission)

For instances, a SME student with student ID 119010001:

A1_SME_119010001.zip:

o A1_SME_119010001_Design.doc o A1_SME_119010001_Source.py o A1_SME_119010001_Output.doc

5% will be deducted if any files are incorrectly named!!!

DESIGN DOCUMENTATION

For the design document provide write-up for the following 2 chapters:

  1. Design:
  2. Describe your strategy for guessing
  3. Describe the core data structures used for tracking the guess history and feedback
  4. Describe the structure of the program (functions, variables and program flow) 2. Test Strategy:
  5. How to verify that your program works as per Scope create a test plan
  6. Describe different plans for different scenarios

TIPS & HINTS

  • Format the feedback for each guess using format() (number guessed, correct : xx, position: xx)
  • Use a list to keep all previous guesses & feedback as strings
  • Beware of variable scope as you might keep a few variables as global such as guess results and guess count.
  • Refer to python website for program styles and naming convention (PEP 8)
  • Try a guessing algorithm (solution) with a simple strategy in 2 parts. The first part is to determine all the correct digits (not concerning the position); then the second part simply takes the digits form part I and reorders them to match the secret number.
  • Split up the digits in logical groups and make first guess attempt for each group. Based on different feedback, identify the digit(s) that is part of the secret number or not. Use the result discovered to sequentially determine the remaining digits one by one. Once all required digits are discovered, simply shuffle the digits until a correct guess is achieved.
  • Gradually optimize your guessing solution with results from part I to make part II more efficient.

OUTPUT SUCCESSFUL GUESS

SECRET NUMBER = 487

Guess 1/15: 123

How many correct digits? 0

Guess 1/15: 123 Correct=0 Exact=0

Guess 2/15: 490

How many correct digits? 1

How many exact digits? 1

Guess 1/15: 123 Correct=0 Exact=0

Guess 2/15: 490 Correct=1 Exact=1

Guess 3/15: 478

How many correct digits? 3

How many exact digits? 1

Guess 1/15: 123 Correct=0 Exact=0

Guess 2/15: 490 Correct=1 Exact=1

Guess 3/15: 478 Correct=3 Exact=1

Guess 4/15: 487

How many correct digits? 3

How many exact digits? 3

Congratulations!! Start a new game (y/n)?

OUTPUT INCORRECT FEEDBACK

SECRET NUMBER = 487

Guess 1/15: 123

How many correct digits? 4

Incorrect feedback, must be < 4 How many correct digits?

SECRET NUMBER = 487

Guess 1/15: 123

How many correct digits? 1

How many exact digits? 2

Incorrect feedback, exact digit must be <= 1!

How many exact digits?

OUTPUT EXCEEDING GUESS LIMIT

SECRET NUMBER = 487

Guess 1/15: 123

How many correct digits? 0

Guess 1/15: 123 Correct=0 Exact=0

Guess 2/15: 490

How many correct digits? 1

How many exact digits? 1

Guess 1/15: 123 Correct=0 Exact=0

Guess 2/15: 490 Correct=1 Exact=1

Guess 3/15: 491

How many correct digits? 1

How many exact digits? 1

Guess 1/15: 123 Correct=0 Exact=0

Guess 2/15: 490 Correct=1 Exact=1

Guess 3/15: 491 Correct=1 Exact=1

Guess 4/15: 431

How many correct digits? 1

How many exact digits? 1

.

.

.

.

.

.

Guess 15/15: 413

Game Over!! Exceeded max. attempts! Start a new game (y/n)?

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Number-Guessing Game (Computer as Guessing Role)
$25