Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 2nd, 2010, 03:19 PM
Registered User
Join Date: Nov 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Nim game

This is what is excepted: The name of the game is 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 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 then 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 gets the first turn and knows the winning strategy can win against the computer.

i have made all the random variables and decided to see if computer is on easy or hard mode, but i can't seem to figure out how to decipher turns?
Reply With Quote

Similar Threads
Thread Thread Starter Forum Replies Last Post
need C++ game programmers kumera C++ Programming 10 September 1st, 2007 11:54 AM
Pong Game Help -XM- BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 4 June 20th, 2007 02:23 PM
Old game review guti Need help with your homework? 0 March 20th, 2007 11:28 AM
Blackjack Game Apocolypse2005 BOOK: Beginning Visual C++ 6 0 June 7th, 2005 12:08 PM
STRATEGIE - GAME! WarKrife C++ Programming 1 August 21st, 2003 08:10 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.