Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I was wondering if you could help me with a beginner JAVA problem. If possible, please use basic code which is easy for a

Hello, I was wondering if you could help me with a beginner JAVA problem. If possible, please use basic code which is easy for a complete beginner to understand. Thank You!

image text in transcribed

This is a well known game with little tricks, The game is played with two players that alternately take marbles from a pile. In each move, a player chooses how many marbles to take. The player must take at least one but at most half of the marbles. Then the other players takes a turn. The player who takes the last marble loses. Write a program in which the computer plays against a human opponent. Use Java, if you want to write it up in Python first you can, but you only turn in Java source for the graders. The program should be in a Class called Nim, and should have a constructor, and all the methods needed to play the game. You should not use static methods, you should create an instance of the Nim class, with instance fields, and call the methods using the dot operator. Generate a random integer between 10 and 100 to represent the original stack of marbles. Generate another random number between 0 and 1 to determine who goes first, computer or player. Generate another random number between 0 and 1 to determine if the computer plays smart or stupid. . . . In stupid mode the computer simply takes a random number of marbles between 1 and n/2 (n being the total marbles). In smart mode the computer takes off enough marbles to make the size of the pile a power of two minus 1 - that is 3,7, 15,31 or 63. (example 202-1 = 3 and 2A3-1-7 and 24-1 = 15). This will always work unless the pile is 1 less than power of 2, so in that case the computer will take a random legal move o o See if you can beat the computer if it goes first can't. , if you programmed it correctly you

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

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

Define data hierarchy.

Answered: 1 week ago

Question

Graph each function. f(x) = 10 -x

Answered: 1 week ago

Question

Understand the purpose and methods of cross-cultural training

Answered: 1 week ago