|
| 1 | +# Instructions |
| 2 | + |
| 3 | +In this exercise, you will simulate a game very similar to the classic card game **Camicia**. |
| 4 | +Your program will receive the initial configuration of two players' decks and must simulate the game until it ends (or detect that it will never end). |
| 5 | + |
| 6 | +## Rules |
| 7 | + |
| 8 | +- The deck is split between **two players**. |
| 9 | + The player's cards are read from left to right, where the leftmost card is the top of the deck. |
| 10 | +- A round consists of both players playing at least one card. |
| 11 | +- Players take turns placing the **top card** of their deck onto a central pile. |
| 12 | +- If the card is a **number card** (2-10), play simply passes to the other player. |
| 13 | +- If the card is a **payment card**, a penalty must be paid: |
| 14 | + - **J** → opponent must pay 1 card |
| 15 | + - **Q** → opponent must pay 2 cards |
| 16 | + - **K** → opponent must pay 3 cards |
| 17 | + - **A** → opponent must pay 4 cards |
| 18 | +- If the player paying a penalty reveals another payment card, that player stops paying the penalty. |
| 19 | + The other player must then pay a penalty based on the new payment card. |
| 20 | +- If the penalty is fully paid without interruption, the player who placed the **last payment card** collects the central pile and places it at the bottom of their deck. |
| 21 | + That player then starts the next round. |
| 22 | +- If a player runs out of cards and is unable to play a card (either while paying a penalty or when it is their turn), the other player collects the central pile. |
| 23 | +- The moment when a player collects cards from the central pile is called a **trick**. |
| 24 | +- If a player has all the cards in their possession after a trick, the game **ends**. |
| 25 | +- The game **enters a loop** as soon as the decks are identical to what they were earlier during the game, **not** counting number cards! |
| 26 | + |
| 27 | +## Examples |
| 28 | + |
| 29 | +A small example of a match that ends. |
| 30 | + |
| 31 | +| Round | Player A | Player B | Pile | Penalty Due | |
| 32 | +| :---- | :----------- | :------------------------- | :------------------------- | :---------- | |
| 33 | +| 1 | 2 A 7 8 Q 10 | 3 4 5 6 K 9 J | | - | |
| 34 | +| 1 | A 7 8 Q 10 | 3 4 5 6 K 9 J | 2 | - | |
| 35 | +| 1 | A 7 8 Q 10 | 4 5 6 K 9 J | 2 3 | - | |
| 36 | +| 1 | 7 8 Q 10 | 4 5 6 K 9 J | 2 3 A | Player B: 4 | |
| 37 | +| 1 | 7 8 Q 10 | 5 6 K 9 J | 2 3 A 4 | Player B: 3 | |
| 38 | +| 1 | 7 8 Q 10 | 6 K 9 J | 2 3 A 4 5 | Player B: 2 | |
| 39 | +| 1 | 7 8 Q 10 | K 9 J | 2 3 A 4 5 6 | Player B: 1 | |
| 40 | +| 1 | 7 8 Q 10 | 9 J | 2 3 A 4 5 6 K | Player A: 3 | |
| 41 | +| 1 | 8 Q 10 | 9 J | 2 3 A 4 5 6 K 7 | Player A: 2 | |
| 42 | +| 1 | Q 10 | 9 J | 2 3 A 4 5 6 K 7 8 | Player A: 1 | |
| 43 | +| 1 | 10 | 9 J | 2 3 A 4 5 6 K 7 8 Q | Player B: 2 | |
| 44 | +| 1 | 10 | J | 2 3 A 4 5 6 K 7 8 Q 9 | Player B: 1 | |
| 45 | +| 1 | 10 | - | 2 3 A 4 5 6 K 7 8 Q 9 J | Player A: 1 | |
| 46 | +| 1 | - | - | 2 3 A 4 5 6 K 7 8 Q 9 J 10 | - | |
| 47 | +| 2 | - | 2 3 A 4 5 6 K 7 8 Q 9 J 10 | - | - | |
| 48 | + |
| 49 | +status: `"finished"`, cards: 13, tricks: 1 |
| 50 | + |
| 51 | +This is a small example of a match that loops. |
| 52 | + |
| 53 | +| Round | Player A | Player B | Pile | Penalty Due | |
| 54 | +| :---- | :------- | :------- | :---- | :---------- | |
| 55 | +| 1 | J 2 3 | 4 J 5 | - | - | |
| 56 | +| 1 | 2 3 | 4 J 5 | J | Player B: 1 | |
| 57 | +| 1 | 2 3 | J 5 | J 4 | - | |
| 58 | +| 2 | 2 3 J 4 | J 5 | - | - | |
| 59 | +| 2 | 3 J 4 | J 5 | 2 | - | |
| 60 | +| 2 | 3 J 4 | 5 | 2 J | Player A: 1 | |
| 61 | +| 2 | J 4 | 5 | 2 J 3 | - | |
| 62 | +| 3 | J 4 | 5 2 J 3 | - | - | |
| 63 | +| 3 | J 4 | 2 J 3 | 5 | - | |
| 64 | +| 3 | 4 | 2 J 3 | 5 J | Player B: 1 | |
| 65 | +| 3 | 4 | J 3 | 5 J 2 | - | |
| 66 | +| 4 | 4 5 J 2 | J 3 | - | - | |
| 67 | + |
| 68 | +The start of round 4 matches the start of round 2. |
| 69 | +Recall, the value of the number cards does not matter. |
| 70 | + |
| 71 | +status: `"loop"`, cards: 8, tricks: 3 |
| 72 | + |
| 73 | +## Your Task |
| 74 | + |
| 75 | +- Using the input, simulate the game following the rules above. |
| 76 | +- Determine the following information regarding the game: |
| 77 | + - **Status**: `"finished"` or `"loop"` |
| 78 | + - **Cards**: total number of cards played throughout the game |
| 79 | + - **Tricks**: number of times the central pile was collected |
| 80 | + |
| 81 | +```exercism/advanced |
| 82 | +For those who want to take on a more exciting challenge, the hunt for other records for the longest game with an end is still open. |
| 83 | +There are 653,534,134,886,878,245,000 (approximately 654 quintillion) possibilities, and we haven't calculated them all yet! |
| 84 | +``` |
0 commit comments