Writing a Nim game in ruby

Discussion in 'Ruby' started by King Kong, Oct 5, 2010.

  1. King Kong

    King Kong Guest

    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/.
    King Kong, Oct 5, 2010
    #1
    1. Advertising

  2. King Kong

    Alex Stahl Guest

    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.
    Alex Stahl, Oct 5, 2010
    #2
    1. Advertising

  3. King Kong

    King Kong Guest

    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/.
    King Kong, Oct 6, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BlackHawke
    Replies:
    12
    Views:
    1,564
    Andrew Thompson
    Jan 26, 2004
  2. Michael Livsey
    Replies:
    3
    Views:
    416
    Michael Livsey
    May 27, 2004
  3. judith
    Replies:
    0
    Views:
    1,644
    judith
    Nov 1, 2006
  4. Max Kubierschky
    Replies:
    10
    Views:
    1,839
    pabloreda
    Mar 31, 2007
  5. Dennis Lee Bieber
    Replies:
    0
    Views:
    425
    Dennis Lee Bieber
    Feb 7, 2010
Loading...

Share This Page