Skip to content

AmitWiley2001/21BottlesGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

W2_Java_Assignment1_Question

Learning Objectives

  • Loops (While / Do While)
  • If ... else Decision construct
  • Random Number Generation
  • Use of Scanner
  • Algorithm Formulation

Problem Statement:

21 Water Bottles Game

  1. In this game, there are 21 Water bottles at the start.
  2. There are 2 players: a. You – Choice decided by input. b. Computer – Choice decided by algorithm.
  3. Each turn involves a player picking up between 1 and 4 Water bottles inclusively.
  4. Whoever picks up the last bottle (21st bottle), is the loser and will have to pay the bill.

Design and implement a game, making use of an Artificially Intelligent algorithm, so that if user is playing first, the Computer would pick up the bottles intelligently each time.

“The Computer should always win.”

The following message will appear at the start of the game.

There are 21 Water bottles...
There are 2 players - Computer and you.
At a time, each one can pick up any no. of bottles between 1 and 4 (inclusive)
Will you like to play first?

If the User types ‘Yes’ and presses ‘Enter’ key, the next lines of output would be

How many you would like to pick up?

If you pick up 3 bottles initially and press ‘Enter’, the intelligent algorithm will decide how many bottles will be selected by the Computer.

For example, the next set of output could be.

How many you would like to pick up? 
3
Computer has picked 2
The bottles remaining are: 16
How many you would like to pick up?

The User must be able to continue the game with Computer, and at every step the remaining bottles need to be displayed appropriately. The no. of remaining bottles will decrease after each round.

How many you would like to pick up? 
2
Computer has picked 3
The bottles remaining are: 11
How many you would like to pick up? 
3
Computer has picked 2
The bottles remaining are: 6
How many you would like to pick up? 
4
Computer has picked 1

As per this artificially intelligent program, the Computer should always win. Once the User is compelled to pick up the last Water bottle, then they are the Loser and would have to pay the bill.

Computer has picked 1
The bottles remaining are : 1
You will have to pick up the last..you are loser

--------Steps to Solve the Problem---------

Step1: Make sure you have Required Tools:

       Java 17 version installed with JAVA_HOME Path Variable

       VS Code IDE with Required Plugins for Java, GIT.

       Git

Step2: Accessing GITHUB Classroom and submiting Assignment:

         Get the Link for GITHUB Classroom.

         Click and Authorize from your GITHUB account.

         Clone the Repository / open through VSCODE IDE.

         Open Water-bottles-game --> src --> main --> Java Files to complete code.

         Solve the Problem Statements through code as detailed in Step 3 below.

         Commit the changes to the repositories, 
         labelling each commit numerically (Commit1, Commit2, etc.).

         Each commit will be tested automatically against the relevant testcases, 
         so you may need to submit several commits as you refine your solution.

         Once you are finished with the assignment (either all test cases passed or not), 
         make sure to lable this commit as "final commit" 
         (this may mean a previous commit passing and 
         you making a slight edit to the latter in order to mark 
         the next commit as being final).

Step3: Solving the Problem:

  Read the Problem Statement carefully

  Go to respective files to complete assignment

  Please follow below pattern in the files where you can complete the code

  /*
  PLEASE INSERT YOUR CODE STRICTLY BETWEEN BELOW COMMENTED LINES
  
  YOUR CODE STARTS HERE
  
  YOUR CODE ENDS HERE
  
  AS TEST CASES ARE EXECUTED USING AUTOMATION TECHNIQUE, REQUEST TO
  
  STRICTLY FOLLOW BELOW MENTIONED RULES
  
  1. THE REST OF THE CODE PROVIDED TO YOU SHOULD BE KEPT STRICTLY UNTOUCHED.
  
  2. YOUR OWN CODE WOULD COME ONLY INSIDE ABOVE-MENTIONED PAIR OF COMMENTS.
  
  3. THE CLASS NAMES, INTERFACE NAMES, METHOD SIGNATURES AND ATTRIBUTE NAMES SHOULD
  
    NOT BE ALTERED OR MODIFIED AND KEPT STRICTLY UNTOUCHED.
    
  4. PLEASE FOLLOW STANDARD JAVA NAMING CONVENTIONS FOR THE PIECE OF CODE YOU
  
   ARE GOING TO PROVIDE INSIDE THE BELOW-MENTIONED PAIR OF COMMENTS.*/
   
//YOUR CODE STARTS HERE

//YOUR CODE ENDS HERE

Note: Every Assignment is being tested with Automation Technique. So please do follow the points mentioned in comments of Java Code.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages