Results 1 to 5 of 5

Thread: Help! Game.

  1. #1
    MIA6 is offline Member
    Join Date
    Oct 2009
    Posts
    17
    Rep Power
    0

    Default Help! Game.

    Hi, Im writing a program for a small game called Nim, so basically a computer versus human player. The legal move is to take a value between 1 and half the size. Whenever if a computer goes first, and the only way to ensure it's gonna win is to take off enough marbles to make the size of the pile a power of two minus 1, that is 3,7,15,31,or 63. I'm just stuck with how to write this method because a computer has to wait for its turn to make the move each time, so it depends on how much the human player takes though computer will make the first move. For loop is not really helping. Can anyone give me some hint? thanks.

    If you can't answer the question above, then can you try to answer the following question, it's easy>!
    In a game class, if you have something like this:

    public void play() {
    while(blah blah) {
    p1.play();
    p2.play();
    }
    Does p1 go first? p2 next? in order? So if i want p2 to go first, then I put p2.play() first? THANKS!
    Last edited by MIA6; 11-08-2009 at 04:06 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    MIA6 is offline Member
    Join Date
    Oct 2009
    Posts
    17
    Rep Power
    0

    Default

    I don't think my code is helpful because it basically just lays out the structure of the player class and I don't even have a basic basic idea of this method that I was asking.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    my guess is that your program is a console program, not a GUI (without code, it's hard to tell), and that your main method will have a loop that continues until a winner is determined. How do you plan to get input? via a Scanner object? If so, simply have the computer go after the player enters text via the scanner.

  5. #5
    MIA6 is offline Member
    Join Date
    Oct 2009
    Posts
    17
    Rep Power
    0

    Default

    What is a console program? Yeah, Scanner will get input from user. Main class is just to call all the methods and to start the game.

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  2. Help with my game!
    By Manikyr in forum New To Java
    Replies: 6
    Last Post: 06-06-2009, 11:09 AM
  3. Game 21
    By aRTx in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2009, 12:33 AM
  4. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 06:00 AM
  5. game
    By amith in forum AWT / Swing
    Replies: 0
    Last Post: 05-19-2008, 05:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •