Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 17-09-2005, 05:00 PM   #1 (permalink)
Broken In
 
Join Date: Oct 2004
Posts: 162
Default a difficult java problem


please help with this java program

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.
You will 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 two. In that case , the computer makes a random legal move.
You will 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.
shivi4 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 18-09-2005, 07:55 PM   #2 (permalink)
Broken In
 
Join Date: Oct 2004
Posts: 162
Default

please help in this problem
shivi4 is offline  
Old 19-09-2005, 03:12 PM   #3 (permalink)
In The Zone
 
#/bin/sh's Avatar
 
Join Date: Apr 2004
Location: 42.65 N 73.76 W
Posts: 213
Default

providing you with a complete solution for that task is quite much work. please be aware, that everyone here tries to help other users in his _free time_ . So you perhaps might work on that we surely help you...

But you start some where...
__________________
\"99 little bugs in the code, 99 bugs in the code, fix one bug, compile it again, 148 little bugs in the code. 148 little bugs in the code....\"
#/bin/sh is offline  
Old 19-09-2005, 05:17 PM   #4 (permalink)
Broken In
 
Join Date: Oct 2004
Posts: 162
Default

you can give module for smart mode alteast
shivi4 is offline  
Old 20-09-2005, 08:44 PM   #5 (permalink)
Broken In
 
Join Date: Oct 2004
Posts: 162
Default

please can someone give smart mode
shivi4 is offline  
 

Bookmarks

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 On


 
Latest Threads
- by topgear
- by Charan

Advertisement




All times are GMT +5.5. The time now is 06:35 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2