if (#x<1) x=s(g) g={} --If either player's hand is empty, shuffle their discard and put it in their hand, empty the discard if (#y<1) y=s(h) h={}
if (#x<1) print('lose') --If either player runs out of cards, the game ends if (#y<1) print('win')
if (btnp(🅾️) and #x*#y!=0) then --if the player tries to draw a card and the game isn't over (if either #x or #y are zero, their product is also zero)
o=x[#x]%13 --o and p are the top cards of each player's hand p=y[#y]%13 --we use 13 because we are only concerned with the value, not the suit c(v,{o,p}) --add the top cards of each player's hand to cards in play x[#x]=z --z is an unused uninitialized variable so it is equal to nil y[#y]=z --this removes the top cards from the players' hands
if (w<1) then --are we currently in a "war"?
If we aren't in a war then
if (#v<3) cls() --if there are only two cards in play, then a new round has begun and we clear the screen ?'1:'..o..' 2:'..p --reveal the cards if(o==p)then --if doubles, start a war w=3 --set the number of cards left to draw for a war to 3 else --not doubles if (o>p) c(g,v) else c(h,v) --If the player wins, they get the cards on the table put in their discard pile v={} --empty the table ?'s:'..(#x+#g-#y-#h)/2+26 --the round is over, display how many cards the player currently has end
If we are in a war
?sub('raw',w,w) --prints the letters of war one at a time w-=1 --reduce the number of cards left in the war --we have already drawn the card at the beginning of the game loop
I've commented every line, I'll go back through and point out some tweetcart tricks.