Poker outcome program challenge!

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Guest

Poker outcome program challenge!

Post by Guest »

Generate five poker hands from a standard deck (52 cards) of cards based on the following rules:

Each hand consists of 5 cards.

Hands should be displayed like this when you are finsihed:

Hand 1 - J (hearts symbol), 3 (diamonds symbol), 10(spades symbol), A (Diamonds), 2(Clubs symbol)
Hand 2 - etc
Hand 3 - etc
Hand 4 - etc
Hand 5 - etc

You can find the codes for the cards here:
ASCII:

Hearts = 003
Diamonds = 004
Clubs = 005
Spades = 006

Good Luck!
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Code: Select all

DEFINT A-Z
'$DYNAMIC
DECLARE FUNCTION ReturnSuit (cardval AS INTEGER)
DECLARE FUNCTION ReturnValue (cardval AS INTEGER)
DECLARE FUNCTION ReturnFace$ (cardvalue AS INTEGER)
RANDOMIZE TIMER

DIM hand AS INTEGER, card AS INTEGER, cardsused(0 TO 51) AS INTEGER, drawn AS INTEGER
CLS
FOR hand = 1 TO 5
  PRINT "Hand" + STR$(hand)
  FOR card = 1 TO 5
    DO
      drawn = INT(RND(1) * 52)
    LOOP UNTIL cardsused(drawn) = 0
    cardsused(drawn) = 1
    PRINT ReturnFace$(ReturnValue(drawn));
    PRINT CHR$(ReturnSuit(drawn) + 3) + ", ";
  NEXT card
  PRINT : PRINT
NEXT hand
END

FUNCTION ReturnFace$ (cardvalue AS INTEGER)
SELECT CASE cardvalue
  CASE 0: ReturnFace$ = "A"
  CASE 1 TO 9: ReturnFace$ = LTRIM$(RTRIM$(STR$(cardvalue + 1)))
  CASE 10: ReturnFace$ = "J"
  CASE 11: ReturnFace$ = "Q"
  CASE 12: ReturnFace$ = "K"
END SELECT
END FUNCTION

FUNCTION ReturnSuit (cardval AS INTEGER)
ReturnSuit = INT(cardval / 13)
END FUNCTION

FUNCTION ReturnValue (cardval AS INTEGER)
SELECT CASE cardval
  CASE 0 TO 12: ReturnValue = cardval
  CASE 13 TO 25: ReturnValue = cardval - 13
  CASE 26 TO 38: ReturnValue = cardval - 26
  CASE 39 TO 51: ReturnValue = cardval - 39
END SELECT
END FUNCTION
Post Reply