Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Writing a Nim game in ruby

Reply
Thread Tools

Writing a Nim game in ruby

 
 
King Kong
Guest
Posts: n/a
 
      10-05-2010
wondering does anyone know how to help with this problem


n and t should be constants in your program, but give them better names
like INITIAL_NUM_MATCHES and MAX_ALLOWED_TO_TAKE. You may assume that
the user plays first and the computer second, and so on.

When n=k*(t+1)+1, for some constant k, your program should always win.
When this is not the case, your program should take a random number of
matches from the pile. If the user makes an error on their turn, your
program should play correctly and win the game.

Your program should have a class called Nim that manages the game
itself. Your main program can manage user input, or you can put this
into another class if you wish.

A good approach to this assignment is to assume that the initial number
of matches is 21 (n=21) and that the maximum number of matches that may
be taken on a turn is 4 (t=4). When you have this problem solved and you
are satisfied your program is correct, extend your program to handle the
more general case where n and t can have other values.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Alex Stahl
Guest
Posts: n/a
 
      10-05-2010
Uhh, what kind of help are you looking for? Or did you just want
someone to do your homework for you?

Sorry for the snark, but it's true - you're not going to learn Ruby if
you just ask other people to do it for you.

On Tue, 2010-10-05 at 17:11 -0500, King Kong wrote:
> wondering does anyone know how to help with this problem
>
>
> n and t should be constants in your program, but give them better names
> like INITIAL_NUM_MATCHES and MAX_ALLOWED_TO_TAKE. You may assume that
> the user plays first and the computer second, and so on.
>
> When n=k*(t+1)+1, for some constant k, your program should always win.
> When this is not the case, your program should take a random number of
> matches from the pile. If the user makes an error on their turn, your
> program should play correctly and win the game.
>
> Your program should have a class called Nim that manages the game
> itself. Your main program can manage user input, or you can put this
> into another class if you wish.
>
> A good approach to this assignment is to assume that the initial number
> of matches is 21 (n=21) and that the maximum number of matches that may
> be taken on a turn is 4 (t=4). When you have this problem solved and you
> are satisfied your program is correct, extend your program to handle the
> more general case where n and t can have other values.




 
Reply With Quote
 
 
 
 
King Kong
Guest
Posts: n/a
 
      10-06-2010
Very true sir but I was short on time and if someone had already done it
would have saved me the effort. Hence it would have helped me.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: still having problems with "Nim". using python 2.6.4 Dennis Lee Bieber Python 0 02-07-2010 08:49 PM
Game programming for kids: looking for open source 2D game developmentkit Max Kubierschky Python 10 03-31-2007 07:18 PM
I need help with card game game of war in GUI enviroment judith Java 0 11-01-2006 06:11 AM
ANN: EvNim uses neuroevolution to evolve an ANN that plays the gameof Nim Michael Livsey Python 3 05-27-2004 04:58 AM
Java Game- Game can't find it's graphics jar file BlackHawke Java 12 01-26-2004 06:14 AM



Advertisments