# Recreate a simplified version of the card game L.L.A.M.A

In LLAMA, you want to dump cards from your hand as quickly as you can, but you might not be able to play what you want.

Each player starts a round with six cards in hand; the deck consists of llama cards and cards numbered 1-6, with eight copies of each. On a turn, the active player can play a card or draw a card. To play a card, you must play the same number as the top card of the discard pile or one number higher (for simplicity, we will follow the rule that if you can play a card of the same number, you will play that card, if not, play the higher card). If a 6 is on the discard pile, you can play a 6 or a llama, and if a llama is on top, you can play another llama or a 1. If you cannot play any cards, you must draw a card.

The round ends when one player empties their hand, who is pronounced as the winner of that round.

Some specifications: 1. The llama cards may have any name, but must be stored as a string (e.g. simply using the value 7 as the llama card is not permitted) 2. If a player draws a card, they may not play the drawn card in the same round again, i.e. their turn ends after drawing a card. 3. We will play the game with four players.

The output should list the turns taken by each player in the following fashion:

1 - 1
2 - 1
3 - 1
4 - 2
1 - 3
2 - draw
3 - 3
4 - 4
.
.
.
1 - 6
2 - llama
game over, 2 wins.


As always in code-golf, the program with the lowest number of bytes wins.

Edits:

In response to the comments, here are a few additional specifications.

• The output may have any format as long as it contains the player number and their action.
• The llama card should be a string composed only of letters, no numbers allowed.
• At the start of a game, there is a single card on the discard pile, i.e. player 1 cannot play any card.
• If the draw deck is empty, the played cards should be reshuffled. As the official rules of the game do not specify what should happen if all cards are drawn and there are no cards in the discard pile, this case does not need to be accounted for.
• There is no input, i.e. the shuffled deck and dealing the hand cards must all be done in the program.
• Since you mentioned code-golf at the bottom, I've added the tag for it. As for the actual challenge with the game of four players, do we take input, or do we output a random game after randomly shuffling and giving each player six cards when we run the program? As for "The llama cards may have any name, but must be stored as a string (e.g. simply using the value 7 as the llama card is not permitted)", "7" is a string. ;) I assume you want to say the llama card can be any string except for numbers? Maybe it's better to only allow letters [a-zA-Z] for the llama card (i.e. "A")? Jan 10 '20 at 8:56
• Also, is the output format flexible, or is that example mandatory and we should also output game over, # wins.? Would it be allowed to simply output a list of pairs (i.e. your example would be [[1,1],[2,1],[3,1],[4,2],[1,3],[2,"draw"],[3,3],[4,4],...,[1,6],[2,"llama"]])? Jan 10 '20 at 8:59
• I feel like "1. The llama cards may have any name, but must be stored as a string (e.g. simply using the value 7 as the llama card is not permitted)" adds nothing to the challenge except making it awkward or impossible in some languages. Jan 10 '20 at 15:03
• @JonathanAllan the existence of llama cards does indeed not change anything about the game mechanics, but as it is a part of the official card game, we will include it here despite the added difficulty to code it. Jan 10 '20 at 15:27
• I have no idea about the game, only this specification ...my comment above is regarding the seemingly arbitrary restriction to a string for the llama card (and not allowing say 7 or 0), which, since we take no input and "The output may have any format as long as it contains the player number and their action" seems somewhat moot. I'd suggest allowing anything which cannot be confused with the other cards (on a slightly separate note I'd also suggest allowing 0-indexing of players and cards). Jan 10 '20 at 18:03

# Jelly, 94 bytes

Ḣ_þⱮOƑƇ€}ṪṪʋ%7ż⁸ʋṢF,Ḣ;€2¦@¥¥¥F;1ịḢɗ}ɗ,;€”d$}ɗḢ€ḢỊƊ?ṭ€1¦⁸ 56Ẋ%7s32s"31,6Ṛç/Ẉ€Ȧ$Ð¿Ṫ€⁺⁺Ḋo”l4R¤ṁżƊ


Try it online!

A set of links which when run niladically returns a list of pairs of [player number, move] where move is l 1 2 3 4 5 6 d. l represents llama and d draw.

# Python 3.8 (pre-release), 401 $$\\cdots\$$ 347 345 bytes

from random import*
d=[*range(7)]*8
shuffle(d)
p=[[d.pop()for i in[1]*6]for j in[1]*4]
o=[*range(1,7)]+['l']
h=[]
s=d.pop()
def g(a):p[n].remove(a);h.append(s);print(f"{n+1}-{o[a]}")
n=3
while all(p):
n=-~n%4
if s in p[n]:g(s)
elif(t:=-~s%7)in p[n]:g(t);s=t
else:
if not d:d=h;h=[];shuffle(d)
p[n]+=[d.pop()];print(f"{n+1}-d")
print(n+1)


Try it online!

• Prints player-card for each move.
• player is 1 to 4.
• card is 1 to 6 or l for llama or d for draw.
• Simply prints winner's number at the end.

# Charcoal, 127 121 bytes

Ｆl123456Ｆ⁸⊞υι≔⟦⟧θＷυ«≔‽υι⊞θι≔Φυ⁻λ⌕υιυ»≔Ｅ⁴Ｅ⁶⊟θη≔⊟θζ≔⁰εＷ⌊η«≔§ηεδＩ⊕ε-¿⊙δ›²﹪⁻ΣκΣζ⁷«Ｆ¬№δζ≔⎇⁼6ζlＩ⊕Σζζ§≔ηεΦδ⁻λ⌕δζζ»«⊞δ⊟θd»⸿≔﹪⊕ε⁴ε


Try it online! Link is to verbose version of code. Outputs l for llama and d for draw. Winner is person who last played a card. Explanation:

Ｆl123456Ｆ⁸⊞υι≔⟦⟧θＷυ«≔‽υι⊞θι≔Φυ⁻λ⌕υιυ»


Create and shuffle the deck.

≔Ｅ⁴Ｅ⁶⊟θη≔⊟θζ


Deal.

≔⁰ε


Start with player 1.

Ｗ⌊η«


Repeat until someone wins.

≔§ηεδ


Get the current player's hand.

Ｉ⊕ε-


Output the current player.

¿⊙δ›²﹪⁻ΣκΣζ⁷«


If they have a playable card:

Ｆ¬№δζ


if they don't have a matching card,

≔⎇⁼6ζlＩ⊕Σζζ


then increment the last discard, rolling over to l for llama;

§≔ηεΦδ⁻λ⌕δζ


remove the playable card from their hand;

ζ


and print their play.

»«⊞δ⊟θd»


Otherwise draw a card and print that action.

⸿


Move to the start of the next line.

≔﹪⊕ε⁴ε


Update to the next player.