Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(+1)
u=unpack --shortening the name of the unpack function


function s(a) --A function to shuffle a stack of cards
    --for each card in a pile, swap it with any card to its right
    for i=1,#a do 
        q=a[i]
        r=i+rnd(#a-i)\1 --i is the index of the card we are swapping, rnd(#a-i)\1 is the number of cards to the right of it
                        --\1, backslash does integer division, which takes the floor of the quotient, is less characters than using flr()
        a[i]=a[r] --the swap
        a[r]=q
    end
    return a --this function doesn't need a return value since it modifies a directly, but I found it useful for shuffling the discard before putting it in your hand
end


function c(a,b) --this function puts a stack of cards, b, on top of the stack of cards, a
    for i=1,#b do
        add(a,b[i]) --adds each card of b in order
    end
end


d={}g={}h={}v={}w=0 --initializing some variables. In order:
                                                            original deck of cards,
                                                            the player's discard pile, 
                                                            the opponent's discard pile, 
                                                            the current cards at stake, 
                                                            how many cards are left to the current war


for i=1,52do d[i]=i end --filling the deck with cards
s(d) --shuffle the deck
x={u(d,1,26)} --the player gets half
y={u(d,27)} --the cpu gets half

Here I use the unpack function to cut the deck by taking a subtable by enclosing the returned tuple with { and }.

::_::        --Usually '_' is used for a label because it would be an awful variable name and so is free
...          --The game loop
flip()goto _ --flip() is necessary to avoid accidentally turning over too many cards