Java - Poker game memory madness


Results 1 to 7 of 7

Thread: Java - Poker game memory madness

  1. #1
    Join Date
    Apr 2003
    Posts
    541

    Java - Poker game memory madness

    Right now im trying to write a program to play some cards(probally something easy likeblackjack at first).

    I made a object for the deck, indivual cards and the hand.

    Im wondering how i should go about using them.

    I was thinking to just mark the cards in the deck as used then create the same card in the hand, but seems kind of waste ful(too more or less identical objects).

    Im wondering if theres a better approach. I have no ideas since i cant use a good old pointer:P

    Thanks

  2. #2
    Join Date
    Apr 2003
    Posts
    541
    Sorry, ment to put this in the programming section, dont know how i manged to pull this one off....

    Mod-ly Help anychance?

  3. #3
    Join Date
    May 2003
    Location
    Some Teritories
    Posts
    367
    Why not use a Vector?
    You create an object called Card with property cardStatus which can be IN_STACK , IN_HAND,IS_DRAWN. Another property isUsed which will change value based on the first one i.e cardStatus = IN_HAND if inHand or cardStatus = IS_DRAWN and false if cardStatus = IN_STACK.
    Then you either make your own object Stack which should extend Vector class or directly use Vector class.
    Then you create a Vector of Cards.
    _________________________
    Registered Linux User #314213
    _________________________
    Desktop 1 : P4 3.2G HT 2GB TWINX CORSAIR 2X120GB S-ATA NV7800GT- Ubuntu 7.04 - Feisty Fawn
    Desktop 2 : P4 2.4G 512MB SDRAM 60GB IntelGMA - Slackware 11 - Fluxbox

  4. #4
    Join Date
    Aug 2004
    Location
    Ohio
    Posts
    9
    I just recently took data structures so my experience is
    limited and I don't know how practical this is, but could you
    have card be as object. Then inside the game's class create
    the deck as a stack, of cards initially sized at 52. Then
    when you deal you'd pop the deck and put it inside an array
    hand
    Slack-Current
    700 MHz Pentium 3
    128 MB RAM

    favorite fortune for now:
    All things are possible,
    except for skiing through
    a revolving door

  5. #5
    Join Date
    Sep 1999
    Posts
    3,202
    When I wrote a poker game for a VB class, I made the deck of cards just an array with 52 spaces - each space contained a number 1-52. 1 == 2 of spades, 13 == ace of spades, 14 == 2 of clubs, etc.

    Pick random numbers 1-52, check to make sure they've not been picked already, and there's your dealt hand - put it in an array. Sort the array. Then if card 1 val == card 2 val + 13, and cards 3-5 are different, you have a pair in hte first position. LOTS of convoluted if-thens later, you can figure out what hand you have.

  6. #6
    Join Date
    Apr 2003
    Posts
    541
    hmmmm

    guessing i should look into vectors and stacks, thanks



    cant believe there wasnt a single person on irc that could of just said that....

  7. #7
    Join Date
    Mar 2002
    Location
    Alton, Illinois, USA
    Posts
    1,126
    I think a stack is perhaps the best solution presented. A stack mimics a card deck the best. Deal a card off the top, pop an item off a stack.

    Although a Stack is just a vector with a few extra methods in Java. Might be trickey to randomize it though. An ArrayList might also be a good idea.
    "You are not beaten until you admit it." --George S. Patton

    "Reading and learning, it's what linux users do"
    "Double clicking" doesn't work on Linux

    G4L | ZSH - The Z Shell

    Apple OS X, FreeBSD, and Smoothwall

Posting Permissions

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