Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.Write a Java program that plays a mathematical game called Taking Stones which is based on the Chinese game of Tsyan-shiz. In this game, the

1.Write a Java program that plays a mathematical game called Taking Stones which is based on the Chinese game of Tsyan-shiz. In this game, the person who runs your program will be the human player and your program will be a simple Artificial Intelligence (AI) that will serve as the other player, as well as provide the narrative for the game and keep score. Your program must keep score impartially while participating in the game, but this is not a difficult task for the computer.

2.The rules of the game are:

a.The human player and the computer will roll a (virtual) pair of dice at the beginning of each game to see who goes first.

b.The player who goes first provides the number of stones that will be in the pile. The number must be between 10 and 50.

c.Each player then removes some number (between 1 and 3) of stones from the pile until one player removes the final stone.

d.The player who goes first:

i.Provides the number of stones to be placed in the pile,

ii.Removes the first set of 1 to 3 stones

e.Other player removes a set of 1 to 3 stones

f.The players then take turns(iteration) until the final stone is removed.

g.The play who removes the final stone is the winner

3.The program must perform the following: (see example output appendix in this document for clarity)

a.Use the System I/O (print(), println(), or (better) printf()) to introduce and describe the game, introduce itself as the AI player, and prompt the human player (the person running your program) for his or her name.

b.The program must use a Scanner object to receive the inputted response.

c.The response must be assigned to a properly typed variable.

d.Uses printf() to display a greeting to the human player that incorporates the name provided in response to the prompt: Welcome <users name> to the game of Taking Stones.

e.The users name must be output in proper name case (i.e., mixed case starting with upper case for the first letter) regardless of the case the user types in.

f.The program will then roll a virtual pair of dice twice,

i.first for the human player

ii.secondly for itself as the AI player,

iii.whichever players roll returns the largest number goes first.

g.The player who wins the roll and goes first will choose the number of stones (10 50) to be placed in the pile,

h.Game play

i.Player chooses a number (1 3) which remove the first set of stones from the pile.

ii.The program must reject invalid entries for these numbers by

1. inform the human player that the number is invalid

2.remind the player of the constraints,

3.prompt the player to re-enter an appropriate number.

iii.AI Player

1.Uses randome number generation to select such a number.

2.Java has two ways to generate random numbers

a.Math.random method from the Java API Math

b.java.util.random Class and the appropriate method from that class, to generate this number for the AI player (as well as for the roll of the pair of dice).

i.When one of the players has won a game, the program must output a congratulatory message naming the winner.

j.After a game has ended the program must ask

One more game? (Y/N):

The user answers with an uppercase or lowercase y or n respectively. Any other input is rejected. If the answer is Y or y, the program will return to step d above and once again initiate the two roles of the dice to determine which player goes first. If the answer is N or n, the program terminates.

4.Include Javadoc class comment following Project Comment Template on the content page.

5.The project requires one files to be turned in - Nimatron.java (the source code of your Taking Stones Game program)

6.Be sure to follow the Programming Project Submission Instructions posted by your instructor on the elearning site. The submission requirements are part of the grading for this assignment.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

Discuss about training and development in India?

Answered: 1 week ago

Question

Explain the various techniques of training and development.

Answered: 1 week ago

Question

Explain the various techniques of Management Development.

Answered: 1 week ago