Write a perl program to design a computer game, Programming Languages

Write a Perl program ghici.pl, one of the simplest computer games. The program should generate a random integer between 1 and 1000 and asks the user to guess it. If the user ?nds the number, the program stops with a message. If not, the program adjusts the interval based on the user's guess and lets him try again. To generate a random integer, use function rand, documented in perldoc perlfunc.

despi@turing> ghici.pl
comp315@turing> ghici.pl
Enter a number between 1 and 1000: 1200
Please stay between 1 and 1000.
Enter a number between 1 and 1000: 500
Enter a number between 500 and 1000: 300
Please stay between 500 and 1000.
Enter a number between 500 and 1000: 750
Enter a number between 500 and 750: sir!
Please enter a number only.
Enter a number between 500 and 750: 625
Enter a number between 625 and 750: 684
Enter a number between 684 and 750: 712
Enter a number between 684 and 712: 694
Enter a number between 684 and 694: 689
Enter a number between 689 and 694: 692

You guessed it in 11 tries.

Notice how the program works:

  • it uses a dichotomic search based on user's answer to adjust the limits.
  • it tests if the answer is a number in between limits
  • it counts the number of tries.

What features would you like to add to this program? Write them down as a comment in the source code of ghici.pl.

Posted Date: 3/12/2013 1:42:43 AM | Location : United States







Related Discussions:- Write a perl program to design a computer game, Assignment Help, Ask Question on Write a perl program to design a computer game, Get Answer, Expert's Help, Write a perl program to design a computer game Discussions

Write discussion on Write a perl program to design a computer game
Your posts are moderated
Related Questions
1. Introduction The Tube Challenge is a Guinness World Records challenge that tests both the physical and mental abilities of the person trying to break it. The main components

Your program can be invoked with option: -d date, where date is entered in dd/mm/yyyy format. In this case, it must only print the following string: Found cookies expiring bef

Pascal program: Exactly what you need to do to generate your empirical data is specific to your individual assignment. However, some rules apply to all of you: 1. The gener

find value of nCr using function

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

Task: This assignment is about writing programmes and Web Services in C#: 1) Develop a console programme that reads a sequence of integer numbers from the console and sorts

How to do socket programming in C

Silver light uses WPF to provide included web handles Microsoft Technologies Silverlight uses WPF to provide included web handles similar to Adobe Display, but with more focus on a

You need to create a simple application for the Note Plus book Store. The interface for the application is shown below:   REQUIRED: 1)  Create all necessary contro

For this assignment you will use the robot/maze simulation example introduced in mini-assignments 0625ma-0627ma to develop a maze-solving program. The program will read a file cont