Here is my first draft of a two tweet card game simulation of the card game war.
In the card game war, the deck is shuffled and each player gets half the cards. The players then simultaneously draw one card at a time, the player who draws a higher card wins the round and takes all the cards drawn that round. If both players draw the same card, then they do a 'war', which means the round continues with each player drawing four cards and comparing the last one. The game ends when one player is out of cards.
u=unpack
function s(a)for i=1,#a do
q=a[i]r=i+rnd(#a-i)\1a[i]=a[r]a[r]=q
end
return a
end
function c(a,b)for i=1,#b do
add(a,b[i])end
end
d={}g={}h={}v={}w=0
for i=1,52do d[i]=i end
s(d)x={u(d,1,26)}y={u(d,27)}::_::
if(#x<1)x=s(g)g={}
if(#y<1)y=s(h)h={}
if(#x<1)print('lose')
if(#y<1)print('win')
if(btnp(🅾️)and#x*#y!=0)then
o=x[#x]%13p=y[#y]%13c(v,{o,p})x[#x]=z y[#y]=z
if(w<1)then
if(#v<3)cls()
?'1:'..o..' 2:'..p
if(o==p)then
w=3
else
if(o>p)c(g,v)else c(h,v)
v={}
?'s:'..(#x+#g-#y-#h)/2+26
end
else
?sub('raw',w,w)
w-=1end
end
flip()goto _
There is still plenty of work to be done, but I will explain this code as it is in another post.