- Sections:-
- Long Story Short
- Algorithm
- Future Developments
Ordinary Number Guessing Game : You have five turns, guess the number between 1 and 100. Winning Probability : 0.05
Intermeditiate Number Guessing Game : Everything is same except one improvement. Here the machine provides you hint like the number you guessed is too low OR the number you guessed is too high. This although provides the user with some insight but that not enough.
The type of number guessing games described above are good for coding practices but actually are boring in nature. I have tried to make it interesting to play.
Suppose gave a wrong guess the following describes how the computer/machine you're using responds:-
This time you were not able to make it up. As a hint, the number lies between 32 and 47. Please try again !!!
Everytime you lose the program will give the range in which correct option lies. But, does the program give you same range No, it will don't.
- First Time you lose : range of 15 numbers
- Second Time you lose : range of 10 numbers
- Third Time you lose : range of 5 numbers
- Fourth Time you lose : range of 3 numbers
The range finder algorithm is used to find upper and lower ends of range so as to give a hint.
- First the programs randomly picks a number from 1 to 100.
- This number and the difference that should be between upper and lower limits of range is passed to the Ranger finder function.
- The algorithm then divides the difference by two and rounds off the number obtained.
- Then the algorithm finds a random number between 0 and difference/2 let's call it A.
- This random number found is then subtracted from the number which was passed as an argument, and the number so obtained is the lower limit of range.
- For the upper end the algorithm adds (difference-A) to the number, this becomes the upper limit of the range.
- At the end both upper limit and lower limits are returned.
- A for loop is used to obtain different Lower and upper limits for different difference values.
- The computer selects 50 as number.
- The difference is 15
- 15/2 = 8 (rounded off value)
- The computer then randomly picks a number ranging from 0 to 8
- Let's say the computer picks number 5.
- Now, 5 is subtracted from 50 and 45 is obtained as lower limit.
- Now, 5 is subtracted from the difference which is 15 and we obtain 10, 10 is added to the 50 and 50 us obtained as upper limit.
- Both 45 : lower limit and 60: upper limt are returned.
- May add Graphical User Interface.
- May add a database to store users scores and to implement a functionality that saves highscores.
- Since, it a simple game so may be in future i may integrate this game with other games of this type to a single platform.