Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 03-06-2007, 11:45 AM   #1
Fully Optimized
 
NeXuS's Avatar
 
Join Date: Dec 2005
Posts: 2,960
Default Need help on java!

Here is my assignment

The Game of Nim

This is a well-known game with a number of variants. We will consider the following variant, which has an interesting winning strategy. Two players 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 player takes a turn. The player who takes the last marble loses.

Write a program in which the computer plays against a human opponent. Generate a random integer between 10 and 100 to denote the initial size of the pile. Generate a random integer between 0 and 1 to decide whether the computer or the human takes the first turn. Generate a random integer between 0 and 1 to decide whether the computer plays smart or stupid.

In stupid mode, the computer simply takes a random legal value (between 1 and n/2) from the pile whenever it has a turn. 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. That is always a legal move, except if the size of the pile is currently one less than a power of 2. In that case, the computer makes a random legal move.

Note that the computer cannot be beaten in smart mode when it has the first move, unless the pile size happens to be 15, 31, or 63. Of course, a human player who has the first turn and knows the winning strategy can win against the computer.
When you implement this program, be sure to use classes Pile, Player, and Game. A player can be either stupid, smart, or human. (Human Player objects prompt for input.)

Here is the pile class

import java.util.Random;
public class Pile
{
private int pileSize;


public Pile()
{
Random randomNumbers = new Random();
pileSize = 10 + randomNumbers.nextInt(91);
}

public int getSize()
{
return pileSize;
}
public void decreaseSize(int input)
{
pileSize = pileSize - input;
}

}

Player class

import java.util.Random;
public class Player
{
boolean stupidMode;
boolean smartMode;
private int computerRandom;
private int human;
private int skill;

public Player()
{
Random randomNumbers = new Random();
computerRandom = randomNumbers.nextInt(2);
stupidMode = false;
smartMode = false;
if (computerRandom == 0)
stupidMode = true;
else
smartMode = true;
}

public void takeMarbles( Pile p )
{
if (!smartMode)
p.decreaseSize(randomNumbers.nextInt(getSize/2);
}

Game class

import java.util.Scanner;
import java.util.Random;
public class Game
{
public static void main(String[] args)
{

int firstTurn;
int computerInput, humanInput;
Scanner keyboard = new Scanner(System.in);
Pile gamePile = new Pile ();
Player humanPlayer = new Player();
Player compPlayer = new Player();

humanPlayer.takeMarbles(gamePile);
compPlayer.takeMarbles(gamePile);
Random randomNumbers = new Random();
firstTurn = randomNumbers.nextInt(2);
if (firstTurn == 0)
{
Input = keyboard.nextInt();
}
else


}
}
__________________

__________________
//Antec 902 V3 Case, Intel i7-2600K (@4.5GHz 1.280V watercooled w/ Antec H2O Kuhler 920), 8GB DDR3 Corsair Vengeance 1866MHz, ASUS P8P67 PRO B3, MSI 3GB N580 GTX Lightning Xtreme (@850MHz/2100MHz), 1TB Samsung Spinpoint F3, Corsair HX850W Pro Series//
//XPS 410 C2D E6400 @ 2.13GHz, 2GB DDR2 667MHz, 250GB HD, eVGA 320mb 8800GTS(605/1900MHz)//
//AMD Athlon XP +2000, Socket A MSI-6390, 768 mb of PC 2100 RAM, AGP ATI RADEON 9600SE//

I <3 TrancE
NeXuS is offline   Reply With Quote
Old 03-06-2007, 01:28 PM   #2
In Runtime
 
Daeva's Avatar
 
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: Need help on java!

so, what exactly is it you need to do? The program compiles fine(with a little error checking and fixing), but it doesn't do anything.
__________________

__________________
**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
http://www.twitter.com/xDaevax
Daeva is offline   Reply With Quote
Old 03-06-2007, 04:29 PM   #3
Solid State Member
 
Kalia's Avatar
 
Join Date: Mar 2004
Posts: 12
Send a message via AIM to Kalia
Default Re: Need help on java!

Heh, wrote this program in C.
Kalia is offline   Reply With Quote
Old 03-08-2007, 05:50 PM   #4
Fully Optimized
 
NeXuS's Avatar
 
Join Date: Dec 2005
Posts: 2,960
Default Re: Need help on java!

Hmmm its a game I pasted the intructions on the beggining before the code.
__________________
//Antec 902 V3 Case, Intel i7-2600K (@4.5GHz 1.280V watercooled w/ Antec H2O Kuhler 920), 8GB DDR3 Corsair Vengeance 1866MHz, ASUS P8P67 PRO B3, MSI 3GB N580 GTX Lightning Xtreme (@850MHz/2100MHz), 1TB Samsung Spinpoint F3, Corsair HX850W Pro Series//
//XPS 410 C2D E6400 @ 2.13GHz, 2GB DDR2 667MHz, 250GB HD, eVGA 320mb 8800GTS(605/1900MHz)//
//AMD Athlon XP +2000, Socket A MSI-6390, 768 mb of PC 2100 RAM, AGP ATI RADEON 9600SE//

I <3 TrancE
NeXuS is offline   Reply With Quote
Old 03-09-2007, 08:54 AM   #5
In Runtime
 
Daeva's Avatar
 
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: Need help on java!

ok, I think I have a solution, give me a little bit to work through it.
__________________
**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
http://www.twitter.com/xDaevax
Daeva is offline   Reply With Quote
Old 03-11-2007, 02:49 PM   #6
Fully Optimized
 
NeXuS's Avatar
 
Join Date: Dec 2005
Posts: 2,960
Default Re: Need help on java!

Thats ok I advanced a little I could run it but couldnt made it work correctly.
__________________

__________________
//Antec 902 V3 Case, Intel i7-2600K (@4.5GHz 1.280V watercooled w/ Antec H2O Kuhler 920), 8GB DDR3 Corsair Vengeance 1866MHz, ASUS P8P67 PRO B3, MSI 3GB N580 GTX Lightning Xtreme (@850MHz/2100MHz), 1TB Samsung Spinpoint F3, Corsair HX850W Pro Series//
//XPS 410 C2D E6400 @ 2.13GHz, 2GB DDR2 667MHz, 250GB HD, eVGA 320mb 8800GTS(605/1900MHz)//
//AMD Athlon XP +2000, Socket A MSI-6390, 768 mb of PC 2100 RAM, AGP ATI RADEON 9600SE//

I <3 TrancE
NeXuS is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 09:52 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0