Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 03-27-2007, 01:37 PM   #1
Fully Optimized
 
NeXuS's Avatar
 
Join Date: Dec 2005
Posts: 2,960
Default JAVA Poker Simulator Project! Help :)

Well here are the instructions

Poker Simulator:

In this assignment, you will implement a simulation of a popular casino game usually called video poker. The card deck contains 52 cards, 13 of each suit. At the beginning of the game, the deck is shuffled. You need to devise a fair method for shuffling. (It does not have to be efficient.) Then the top five cards of the deck are presented to the player. The player can reject none, some, or all of the cards. The rejected cards are replaced from the top of the deck. Now the hand is score. At the very minimum, your project should have at least a Card class and a driver class. Your program should pronounce it to be one of the following:

* No pair - The lowest hand, containing five separate cards that do not match up to create any of the hands below.
* One pair - Two cards of the same value, for example two queens.
* Two pairs - Two pairs, for example two queens and two 5's.
* Three of a kind - Three cards of the same value, for example three queens.
* Straight - Five cards with consecutive values, not necessarily of the same suit, such as 4, 5, 6, 7, and 8. The ace can either precede a 2 or follow a king.
* Flush - Five cards, not necessarily in order, of the same suit.
* Full House - Three of a kind and a pair, for example three queens and two 5's
* Four of a Kind - Four cards of the same value, such as four queens
* Straight Flush - A straight and a flush: Five cards with consecutive values of the same suit
* Royal Flush - The best possible hand in a poker. A 10, jack, queen, king, and ace, all of the same suit.

If you are so inclined, you can implement a wager. The player pays a JavaDollar for each game, and wins according to the
following payout chart:
Hand Payout

Royal Flush 250
Straight Flush 50
Four of a Kind 25
Full House 6
Flush 5
Straight 4
Three of a kind 3
Two Pair 2
Pair of Jacks 1
or Better

Code located at my last post
V
V
V
__________________

__________________
//Antec 902 V3 Case, Intel i7-2600K (@4.5GHz 1.280V watercooled w/ Antec H2O Kuhler 920), 8GB DDR3 Corsair Vengeance 1866MHz, ASUS P8P67 PRO B3, MSI 3GB N580 GTX Lightning Xtreme (@850MHz/2100MHz), 1TB Samsung Spinpoint F3, Corsair HX850W Pro Series//
//XPS 410 C2D E6400 @ 2.13GHz, 2GB DDR2 667MHz, 250GB HD, eVGA 320mb 8800GTS(605/1900MHz)//
//AMD Athlon XP +2000, Socket A MSI-6390, 768 mb of PC 2100 RAM, AGP ATI RADEON 9600SE//

I <3 TrancE
NeXuS is offline   Reply With Quote
Old 03-27-2007, 03:13 PM   #2
Fully Optimized
 
UK31337's Avatar
 
Join Date: Feb 2005
Posts: 2,776
Default Re: JAVA Poker Simulator Project! Help :)

Sorry, can't see what you're asking/what the problem is??
__________________

UK31337 is offline   Reply With Quote
Old 03-28-2007, 12:08 PM   #3
In Runtime
 
Daeva's Avatar
 
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: JAVA Poker Simulator Project! Help :)

I wrote a similar program to this, and mine looked similar to yours but I realised something. In your example, it won't be a fair deal because, theoretically, you could be dealt the same card over and over, you could get 6 3 of hearts because the inital array of values is not being modified. You may want to consider a multi-dimensional array instead of two separate "suit" and "rank" array's. However, after working through it, this is the most efficient way I can think to do it, and at least for the first part, you have to use a multi-dimensional array. It doesn't play yet, but you should be able to make the game playable with a workable deck of cards. Hope this helps.
Code:
import java.util.Random;
import java.util.Scanner;
public class cardsGame {
 private String deck[][] = new String[13][4]; // basic deck of cards
 // in this array, each of the 13 cards will have it's own suit
 private String suits[][] = new String[13][4]; // this is used to output suits
 private String shuffledDeck[] = new String[52]; // this is the deck that is dealt from
 private String shuffledSuit[] = new String[52]; // this is used to keep track of suits
 private String playerCards[] = new String[5]; // this is used to keep track of player's cards
 private String playerSuits[] = new String[5]; // this is used to keep track of player's card's suits
 private static final int BANK = 50;
 private int myBank;
 private int card;
 private int suit;
 private int wager = 0;
 public cardsGame() {
  play();
 } // end default no-argument constructor
 public void populateDeck() {
  for (int x = 0; x <13; x++) {
   for (int y = 0; y<4; y++) {
	switch(x) {
	 case 9:
	  deck[x][y] = "J";
	  break;
	 case 10:
	  deck[x][y] = "Q";
	  break;
	 case 11:
	  deck[x][y] = "K";
	  break;
	 case 12:
	  deck[x][y] = "A";
	  break;
	 default:
	  deck[x][y] = "" + (x+2);
	  break;
	} // end switch
	switch(y) {
	 case 0:
	  suits[x][y] = "Spades";
	  break;
	 case 1:
	  suits[x][y] = "Clubs";
	  break;
	 case 2:
	  suits[x][y] = "Diamonds";
	  break;
	 case 3:
	  suits[x][y] = "Hearts";
	  break;
	} // end switch
   } // end for
  } // end for
 } // end method populateDeck
 public void shuffle() {
  for (int x = 0; x<52; x++) {
   do {
	card = (int)(13*Math.random());
	suit = (int)(4*Math.random());
   } while(deck[card][suit].equals("0"));
   //playerDeck[card][suit]
   shuffledDeck[x] = deck[card][suit];
   shuffledSuit[x] = suits[card][suit];
   deck[card][suit] = "0";
  } // end for
 } // end method shuffle
 public void play() {
  Scanner input = new Scanner(System.in);
  myBank = BANK;
  populateDeck();
  shuffle();
  System.out.printf("\n\t%s\n\n%s\n\n%s\n","Welcome to Java Poker!", "You can press <ctrl> z at any time to exit the program.","Please enter your wager:");
  deal(); // deal cards
  System.out.print("You have " + myBank + " credits.\n");
  System.out.printf("Amount:");
  while((getWager() <=10 && getWager() >0) && getWager() <= myBank) {
   wager = input.nextInt();
  }

 } // end method play
 public int getWager() {
  return wager;
 } // end method getWager
 public void deal() {
  System.out.printf("\t%s\n%s\n","Your Hand","------------------------");
  for (int x = 0; x<5; x++) {
   do {
	playerCards[x] = shuffledDeck[x];
   } while(shuffledDeck[x] == "0");
   shuffledDeck[x] = "0";
   do {
	playerSuits[x] = shuffledSuit[x];
   } while(shuffledSuit[x] == "0");
   shuffledSuit[x] = "0";
   System.out.print(playerCards[x] + " of " + playerSuits[x] + ".\t" + x + "\n");
  } // end for loop
  System.out.print("------------------------\n");
 } // end method deal
 public static void main(String args[]) {
  cardsGame cg = new cardsGame();
 } // end method main

}// end class cardsGame
__________________
**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
http://www.twitter.com/xDaevax
Daeva is offline   Reply With Quote
Old 03-28-2007, 04:50 PM   #4
Fully Optimized
 
NeXuS's Avatar
 
Join Date: Dec 2005
Posts: 2,960
Default Re: JAVA Poker Simulator Project! Help :)

Thanks but the thing is that havent seen multi dimensional arrays, so it would illegal if I use them. If you use my two classes the SimpleDeck class creates a deck when initDeck method and you can set ranks and the suits methods. But I still cant get my deck to shuffle the cards.
__________________
//Antec 902 V3 Case, Intel i7-2600K (@4.5GHz 1.280V watercooled w/ Antec H2O Kuhler 920), 8GB DDR3 Corsair Vengeance 1866MHz, ASUS P8P67 PRO B3, MSI 3GB N580 GTX Lightning Xtreme (@850MHz/2100MHz), 1TB Samsung Spinpoint F3, Corsair HX850W Pro Series//
//XPS 410 C2D E6400 @ 2.13GHz, 2GB DDR2 667MHz, 250GB HD, eVGA 320mb 8800GTS(605/1900MHz)//
//AMD Athlon XP +2000, Socket A MSI-6390, 768 mb of PC 2100 RAM, AGP ATI RADEON 9600SE//

I <3 TrancE
NeXuS is offline   Reply With Quote
Old 03-28-2007, 05:11 PM   #5
In Runtime
 
Daeva's Avatar
 
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: JAVA Poker Simulator Project! Help :)

it would be illegal if you went above and beyond the requirements?
__________________
**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
http://www.twitter.com/xDaevax
Daeva is offline   Reply With Quote
Old 03-28-2007, 07:06 PM   #6
In Runtime
 
Daeva's Avatar
 
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: JAVA Poker Simulator Project! Help :)

Well, it's not the way I would do it... But you can do it that way i suppose. Keep in mind though that it is more work for the system running the application because it has to devote more memory to an array of class objects as opposed to an array of strings. You might try creating a new class called shuffledDeck, or something like that. And basically just follow my logic, but using classes. Specifically this portion of my code:
Code:
public void shuffle() {
for (int x = 0; x<52; x++) {
do {
	card = (int)(13*Math.random());
	suit = (int)(4*Math.random());
} while(deck[card][suit].equals("0"));
//playerDeck[card][suit]
shuffledDeck[x] = deck[card][suit];
shuffledSuit[x] = suits[card][suit];
deck[card][suit] = "0";
} // end for
} // end method shuffle
Only instead of using my array, use your array of classes:
Code:
// declare this variable as a class-wide so that shuffle() has access to it
private int myRank, mySuit; // variables that will be assigned random numbers
private ShuffledDeck[] sd; // new array of shuffledDeck objects
public void shuffle() {
sd = new shuffledDeck[52];
for (int x = 0; x<52; x++) {
do {
myRank = (int)(13*Math.random());
mySuit = (int)(4*Math.random());
} while(theDeck[x].getRank().equals("0"));
/* the purpose for the above code is to continuously generate random numbers while the value of the element of the array of classes is 0, which in a regular deck of cards can't happen */
sd[x] = new shuffledDeck([theDeck[x].getRank().Value()], theDeck[x].getSuit().Value()]);
theDeck[x] = "0"; // initalize the value that was grabbed to 0
} // end for
} // end method shuffle
I didn't compile and test that, because I didn't re-enter your program, the syntax isn't 100% correct, but you can sort of follow where I am going I hope.
__________________
**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
http://www.twitter.com/xDaevax
Daeva is offline   Reply With Quote
Old 04-11-2007, 04:54 PM   #7
Fully Optimized
 
NeXuS's Avatar
 
Join Date: Dec 2005
Posts: 2,960
Default Re: JAVA Poker Simulator Project! Help :)

I finally got all the deck working all shuffled each start im starting to do the game, but im having trouble assigning the first 5 cards of the deck to an array called hand that holds 5 card. Now I have to get the game working ill post the code later!
__________________
//Antec 902 V3 Case, Intel i7-2600K (@4.5GHz 1.280V watercooled w/ Antec H2O Kuhler 920), 8GB DDR3 Corsair Vengeance 1866MHz, ASUS P8P67 PRO B3, MSI 3GB N580 GTX Lightning Xtreme (@850MHz/2100MHz), 1TB Samsung Spinpoint F3, Corsair HX850W Pro Series//
//XPS 410 C2D E6400 @ 2.13GHz, 2GB DDR2 667MHz, 250GB HD, eVGA 320mb 8800GTS(605/1900MHz)//
//AMD Athlon XP +2000, Socket A MSI-6390, 768 mb of PC 2100 RAM, AGP ATI RADEON 9600SE//

I <3 TrancE
NeXuS is offline   Reply With Quote
Old 04-12-2007, 03:27 PM   #8
Fully Optimized
 
NeXuS's Avatar
 
Join Date: Dec 2005
Posts: 2,960
Default Re: JAVA Poker Simulator Project! Help :)

Ok here is the code I am having a problem assining the first cards of the deck to my hand. All the classes reference each other SimpleCard and SimpleDeck are working I just need to make the Game class work. Help me I get the error array required, but SimpleDeck found.

SimpleCard Class

public class SimpleCard
{
private String rank;
private String suit;
public SimpleCard(String r, String s)
{
rank = r;
suit = s;
}
public SimpleCard()
{
rank = " ";
suit = " ";
}

public void setSuit(String s)
{
suit = s;
}
public void setRank(String s)
{
rank = s;
}
public String getSuit()
{
return suit;
}
public String getRank()
{
return rank;
}
public String toString()
{
String str;
str = "Card " + rank + " of " + suit;
return str;
}
public void swapCards(SimpleCard otherCard)
{
SimpleCard temp= new SimpleCard(this.rank, this.suit);

this.rank = otherCard.rank;
this.suit = otherCard.suit;

otherCard.rank = temp.rank;
otherCard.suit = temp.suit;
}

}


SimpleDeck Class

import java.util.Random;
public class SimpleDeck
{
private SimpleCard[] theDeck;
Random randomNumbers = new Random();
public SimpleDeck()
{
theDeck = new SimpleCard[52];
initDeck();
setSuits();
setRanks();
shuffle();
}
public void initDeck()
{
for(int i = 0; i < theDeck.length; i++)
theDeck[i] = new SimpleCard();
}
public void setSuits()
{
String[] suitName = {"Hearts", "Spades", "Diamonds", "Clubs"};
for (int i = 0; i < theDeck.length; i++)
{
theDeck[i].setSuit(suitName[i / 13]);
}
}
public void setRanks()
{
String[] rankName = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
for (int i = 0; i < theDeck.length; i++)
{
theDeck[i].setRank(rankName[i % 13]);
}
}
public void printDeck()
{
for (int i = 0; i < theDeck.length; i++)
{
System.out.println(theDeck[i].getRank() + " of " + theDeck[i].getSuit());
}
}

public void shuffle()
{
for (int i = 0; i < theDeck.length; i++)
{
theDeck[i].swapCards(theDeck[randomNumbers.nextInt(52)]);
}

}

}

Game Class

public class Game
{
public static void main(String[] args)
{
SimpleDeck gameDeck = new SimpleDeck();
String[] hand = new String[5];
System.out.println("Welcome to Video Poker");
System.out.println("Your hand");
int j = 0;
for (int i = 0; i < 5; i++)
{
hand[i] = gameDeck[j];
j++;
}

}
}
__________________
//Antec 902 V3 Case, Intel i7-2600K (@4.5GHz 1.280V watercooled w/ Antec H2O Kuhler 920), 8GB DDR3 Corsair Vengeance 1866MHz, ASUS P8P67 PRO B3, MSI 3GB N580 GTX Lightning Xtreme (@850MHz/2100MHz), 1TB Samsung Spinpoint F3, Corsair HX850W Pro Series//
//XPS 410 C2D E6400 @ 2.13GHz, 2GB DDR2 667MHz, 250GB HD, eVGA 320mb 8800GTS(605/1900MHz)//
//AMD Athlon XP +2000, Socket A MSI-6390, 768 mb of PC 2100 RAM, AGP ATI RADEON 9600SE//

I <3 TrancE
NeXuS is offline   Reply With Quote
Old 04-12-2007, 04:31 PM   #9
In Runtime
 
Daeva's Avatar
 
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: JAVA Poker Simulator Project! Help :)

In the game class, when you create an object of the SimpleDeck class named gameDeck, it's not declared as an array. then later, you attempt to assign a value to the array that you never created.
I didn't test it, but changing the code to :
SimpleDeck gameDeck[] = new SimpleDeck();
__________________
**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
http://www.twitter.com/xDaevax
Daeva is offline   Reply With Quote
Old 04-12-2007, 05:03 PM   #10
Fully Optimized
 
NeXuS's Avatar
 
Join Date: Dec 2005
Posts: 2,960
Default Re: JAVA Poker Simulator Project! Help :)

I tried I get:
Incompatible types- found SimpleDeck but expected SimpleDeck[]
__________________

__________________
//Antec 902 V3 Case, Intel i7-2600K (@4.5GHz 1.280V watercooled w/ Antec H2O Kuhler 920), 8GB DDR3 Corsair Vengeance 1866MHz, ASUS P8P67 PRO B3, MSI 3GB N580 GTX Lightning Xtreme (@850MHz/2100MHz), 1TB Samsung Spinpoint F3, Corsair HX850W Pro Series//
//XPS 410 C2D E6400 @ 2.13GHz, 2GB DDR2 667MHz, 250GB HD, eVGA 320mb 8800GTS(605/1900MHz)//
//AMD Athlon XP +2000, Socket A MSI-6390, 768 mb of PC 2100 RAM, AGP ATI RADEON 9600SE//

I <3 TrancE
NeXuS is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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



All times are GMT -5. The time now is 12:56 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0