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

6

1

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.

RollingCompass

Posted 2020-01-10T08:28:51.647

Reputation: 63

2Since 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")? – Kevin Cruijssen – 2020-01-10T08:56:27.783

2Also, 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"]])? – Kevin Cruijssen – 2020-01-10T08:59:06.877

1I 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. – Jonathan Allan – 2020-01-10T15:03:31.903

@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. – RollingCompass – 2020-01-10T15:27:52.133

1I 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). – Jonathan Allan – 2020-01-10T18:03:54.247

Having answered the OP I concur with @Johnathan. It's a nontrivial problem and it's code golf. Adding the llama and 1-base restriction just added more bytes on top of an already quite big code golf program. Be nice to be able to 0-base or 1-base the players id too. And to be able to output player and card/draw more freely (eg player space card/draw). – Noodle9 – 2020-01-11T00:12:35.377

Answers

0

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.

Nick Kennedy

Posted 2020-01-10T08:28:51.647

Reputation: 11 829

0

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.

Noodle9

Posted 2020-01-10T08:28:51.647

Reputation: 2 776

0

Charcoal, 127 bytes

Fl123456F⁸⊞υι≔⟦⟧θWυ«≔‽υι⊞θι≔Φυ⁻λ⌕υιυ»≔E⁴E⁶⊟θη≔⊟θζ≔⁰εW⬤ηκ«≔§ηεδ¿⊙δ›²﹪⁻ΣκΣζ⁷«F¬№δζ≔⎇⁼6ζlI⊕Σζζ§≔ηεΦδ⁻λ⌕δζI⊕ε-ζ⸿»«⊞δ⊟θI⊕ε-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:

Fl123456F⁸⊞υι≔⟦⟧θWυ«≔‽υι⊞θι≔Φυ⁻λ⌕υιυ»

Create and shuffle the deck.

≔E⁴E⁶⊟θη≔⊟θζ

Deal.

≔⁰ε

Start with player 1.

W⬤ηκ«

Repeat until someone wins.

≔§ηεδ

Get the current player's hand.

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

If they have a playable card:

F¬№δζ

if they don't have a matching card,

≔⎇⁼6ζlI⊕Σζζ

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

§≔ηεΦδ⁻λ⌕δζ

remove the playable card from their hand;

I⊕ε-ζ⸿

and print their play.

»«⊞δ⊟θI⊕ε-d⸿»

Otherwise draw a card and print that action.

≔﹪⊕ε⁴ε

Update to the next player.

Neil

Posted 2020-01-10T08:28:51.647

Reputation: 95 035