Pack of cards.

Hi,

I’m just wondering is there a really really really easy way of generating a normal set of cards in Codea?
Meaning picking randomly from the 52 and never picking the same card twice and checking for winning combinations?

is there a very very simple way of doing this that a complete brain dead failure like me can actually grasp and understand? (Without using 2 billion “if” statements to check all possibilities)

Note: I’m not begging for you guys to write the code, I’m just wondering if there is a simple understandable solution so all I really need is a yes or no. :slight_smile:

https://coolcodea.wordpress.com/2013/04/22/39-working-with-playing-cards/

Thanks, I had a read at that and oh my word it’s complex but it does answer my question. Can delete this thread now, thank you.

@mene but what do you want exactly? Just a random card list? or the list PLUS the graphics to draw cards on the display?

@Mene Here’s a simple example I had.

function setup()
    rectMode(CENTER)
    suit={"??","??","??","??"}
    nbr={"2","3","4","5","6","7","8","9","10","J","Q","K","A"}
    deck={}
    createDeck()
    getCard=true
end

function draw()
    background(31, 98, 114, 255)
    if getCard then
        getCard=false
        randomCard()
        c=v%13+1
        s=math.ceil(v/13)
    end
    fill(255)
    rect(WIDTH/2,HEIGHT/2,125,200)  
    fontSize(60)
    text(suit[s],WIDTH/2,HEIGHT/2) 
    if s<3 then
        fill(255,0,0)  
    else
        fill(0)
    end
    text(nbr[c],WIDTH/2-30,HEIGHT/2+70)  
    text(nbr[c],WIDTH/2+30,HEIGHT/2-70)  
    fontSize(20)
    fill(255)
    text(str,WIDTH/2,HEIGHT-100)      
end

function touched(t)
    if t.state==BEGAN then
        getCard=true
    end
end

function createDeck()
    str="Tap screen for next card"
    for z=1,52 do
        deck[z]=z
    end
end

function randomCard()
    if #deck>0 then
        d=math.random(#deck)
        v=deck[d]
        table.remove(deck,d)
    else
        str="End of deck\
press program restart"
        -- createDeck()
    end
end

@Mene Here’s a link to another card example. One of my versions there determines a best hand of 5 cards.

http://codea.io/talk/discussion/5037/codea-project