I'm lost, and it seems so simple?? Please Help

Discussion in 'Programming' started by misery89, Sep 24, 2007.

  1. #1
    I'm soo lost with this, seemingly simple problem.
    I know I have to use arrays or something, please take a look and help if you're able. Thank you so much.

    A very simple game is played by two players. 5 rows of sticks are arranged with the first row consisting of 1 stick, 2nd row consisting of 2 sticks and so on.

    Players take turns; they can remove any number of sticks they want, but they must all be from the same row. The player who wins is the one who takes the last stick. Construct a program that allows two people to play this game.

    Your game should alternate between two players, first letting player A make a move, and then letting player B, etc. Before each move the board should be printed out. After each move the game should be checked to see if the player has won. If not the players switch turns and play continues.

    You will need code that does the following:

    • So the players can see how many sticks are left in each row you should print out an
    easily understood visual representation, not just numeric counts of sticks and rows.

    E.g., use vertical bars (“ | ”) for each stick left in the game and use 5 lines to show the entire board.

    • Ask for how many sticks and from which row the user wants to remove sticks, then ask
    how many, and then do so. You do not need to check that the responses are valid.

    • Determine whether the player has won or not.
    When the game is over you should emit a message indicating who won.
     
    misery89, Sep 24, 2007 IP
  2. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Despite your very sad user name :( I don't think any of us here are gonna do your homework for you.

    Besides, you've given us nothing to go on. For example, what language are you supposed to write this in :confused: ?

    edit: Didn't mean to sound harsh. Post back with the language, and we'll try and get you going in the right direction.
     
    sea otter, Sep 24, 2007 IP
  3. misery89

    misery89 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    My username has nothing to do with it.
    I've been a registered member for a while.

    The language is Java.

    I don't know how to make 'n' number of sticks disappear when chosen.

    for example: system.out.println("how many sticks would you like to take away?");

    how would I make that many " | " sticks, disappear.

    Also, how do I designate a row of sticks so the program removes the correct row when asked.
     
    misery89, Sep 25, 2007 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Dont write java at all so cant help with the technicality of the code itself but the theory seems straight forward enough

    Have an array with 5 items each item representing a the number of sticks left in a the corresponding row, so to start with the array would be 1, 2, 3, 4, 5

    When someone removes sticks simply deduct that number from the corresponding array item. So if the first move was to remove 2 sticks from row 3 the array would then look like 1, 2, 1, 4, 5

    I am not sure you would make the | disappear from the board as much as redraw the board after each move. To draw it just needs something like a nested loop, the outer loop represents each row and just adds a line break after each inner loop. The inner loop conducts as many loops as the number in the corresponding array item (so for row 3 it would be 1 and row 4, 4) drawing the | in each loop
     
    AstarothSolutions, Sep 26, 2007 IP
  5. misery89

    misery89 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I truly appreciate your suggestion, although I've found out I'm not allowed to use arrays.

    Any other, more basic methods to complete this?
     
    misery89, Sep 26, 2007 IP
  6. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #6
    if you cant have an arrany then 5 variables, one for each row each holding the number of sticks left row1=1 row2=2 row3=3 etc
     
    AstarothSolutions, Sep 27, 2007 IP
  7. misery89

    misery89 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you for your consistency,
    if I was to do that, how would that be able to print out a new Board.
    Or table.

    if it's system.out.println(" | ");
    for the first line for example.

    how could that be assigned to an interger "a"
     
    misery89, Sep 27, 2007 IP