Connecting Tech Pros Worldwide Help | Site Map

Nim Game

Newbie
 
Join Date: Oct 2009
Posts: 3
#1: Oct 2 '09
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2. public class GamePlayer
  3. {
  4.     public static void main(String[] args)
  5.     {        
  6.         do
  7.         {
  8.             String gameName = JOptionPane.showInputDialog(null,
  9.                                       "What game do you wish to play?" +
  10.                                                 "\n" + "Nim  TicTacToe  BlackJack");                                
  11.             InteractiveGame game;        
  12.  
  13.             if (gameName.equalsIgnoreCase("Nim"))
  14.                 game = new DummyGame();
  15.             else
  16.                 game = new DummyGame();
  17.  
  18.             while ( !game.isCompleted())
  19.             {
  20.                 if (game.isPlayersTurn())
  21.                 {
  22.                     String move = inputMove(game);
  23.                     game.makePlayersMove(move);
  24.                 }
  25.                 else
  26.                     game.makeComputersMove();
  27.             }
  28.             String message = (game.playerHasWon() ?
  29.                               "Congratulations! You WON" :
  30.                                     "Better Luck Next Time"    );
  31.             JOptionPane.showMessageDialog(null, message);
  32.  
  33.         } while ( playingAgain() );
  34.     }
  35.  
  36.     public static String inputMove(InteractiveGame game)
  37.     {
  38.         String move;
  39.         do
  40.         {
  41.             move = JOptionPane.showInputDialog(null, game + "\n" + "Your Move?");
  42.  
  43.             if (!game.isValidMove(move))
  44.                 JOptionPane.showMessageDialog(null, move + " is an INVALID move");
  45.  
  46.         } while (!game.isValidMove(move));
  47.  
  48.         return move;
  49.     }
  50.  
  51.     public static boolean playingAgain()
  52.     {
  53.         return JOptionPane.showInputDialog(null,
  54.                             "PlayAgain? OK to continue  CANCEL to quit") != null;
  55.     }
  56. }
Attached Files
File Type: txt Requirements.txt (3.2 KB, 48 views)
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#2: Oct 3 '09

re: Nim Game


Please take the time to research the problem before you post your question. The experts here are more than willing to help you with a specific problem but you have to do your part to learn the basics and also formulate a specific question we can help with. Please take the time to read over Read This First.

Before posting any question you are expected to attempt to find and work on a solution. When you find a specific problem with your attempt, that is the time to post here requesting assistance with any difficulties you have or about a particular function of the code that you don't know how to achieve. When posting your problem, details of the problem itself and where it's found are the bare minimum information required. The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you.

Code may be posted for reference purposes, but please don't expect us to work out the meaning of your problem by reverse-engineering your code. The question you post must make sense in its own right.
Newbie
 
Join Date: Oct 2009
Posts: 3
#3: Oct 3 '09

re: Nim Game


I wonder if you are an angel. angels and God are the only one that know things from scratch. you are going to tell me you know every single program you see. JAJA the majority of experts cheat from other programs and they steal other peoples programs to later charge for them. thank you for not helping. I don't need your help
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#4: Oct 3 '09

re: Nim Game


Amelia722 I would love to help you but I'm not going to sit down and read through your code and your assignment requirements to figure out what you are doing...or not doing...or doing incorrectly.

If you want help, then you have to specify what you need help with. It is unfair to expect anyone to sit down and do your homework for you. It's unfair to the experts because it's a waste of their time...and it's unfair to you because you won't learn anything from it.

I would be happy to help you if you have a question that is reasonable. I certainly don't know everything about your game or about Java for that matter, but I would do my best to help you through a specific problem that you are having with a specific piece of code. I am sure that the other Java experts here on bytes would also be delighted to help too!

Please be more reasonable.
Formulate a proper question and ask it.

Don't just post a bunch of requirements and some random half-working code and expect the experts here to know what to do with it.

-Moderator Frinny
Newbie
 
Join Date: Oct 2009
Posts: 3
#5: Oct 9 '09

re: Nim Game


OK can you be so kind and help me with this program questions thank you

How many permutations of the letters ABCDEFGH contain the string BCA and BEF?


How many bit strings of length 12 contain exactly three 1s?
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#6: Oct 10 '09

re: Nim Game


Quote:

Originally Posted by amelia722 View Post

How many permutations of the letters ABCDEFGH contain the string BCA and BEF?

Zero, if a C follows a B an E can't follow a B.

Quote:

Originally Posted by amelia722 View Post

How many bit strings of length 12 contain exactly three 1s?

12*11*10/(3*2*1)

What has this to do with Java?

kind regards,

Jos
Reply