Beggar my neighbor is a deterministic game in which 2 players get dealt half of a 52 card deck, and the objective is to obtain the entire deck.
On their turn, each player places the top card of their deck on the table. If that card is a face card (the ace is a face card), the opposite player then must turn over a certain number of cards from the top of their deck until they reveal a face card as well (at which point the roles reverse). If they can't, the player that last played a face card takes the pile of cards on the table, and adds it to the bottom of their deck. the winning player then continues the game.
The game ends when a player has obtained all the cards in the deck. Note that if a player has all the face cards, their victory is guaranteed, but it is not achieved yet and they need to take all the cards from their opponent to properly end the game.
The number of tries someone has to turn over a face card in response to a face card depends on the face card:
- Jack : 1 card
- Queen: 2 cards
- King : 3 cards
- Ace : 4 cards
Here's an example trick:
I turn over a 10.
They turn over an ace.
I turn over a 5, a 7, and a Jack.
They turn over a Queen
I turn over a 2 and a 9.
They win this trick, sweep the table and it is their turn next.
Hopefully by now it's becoming clear that this game is completely deterministic and that there is no strategy; the entire game is decided by how the cards are shuffled and dealt. The longest known terminating game is 1164 tricks long, but it is possible for a game to go on forever (you won't need to handle this here)
The task
Given a deck of cards, output the number of tricks and cards it takes to reach the end of the game.
IO
You may take the deck however you see fit. You may forgo taking the cards color as input, as it has no bearing on play. Since numbered cards also are fungible, a standard way of representing a deck is as a pair of strings like so:
---K---Q-KQAJ-----AAJ--J-- and ----------Q----KQ-J-----KA (this game will be infinite, don't use it as a test case!)
You may choose to represent face cards as the number of cards they ask for. Generally speaking, within reason, feel free to use a format convenient for you as long as it doesn't trivialize the meat of the challenge (simulating the game and how the cards rotate). This isn't an input parsing challenge.
Assume the game is finite. You may assume that a game cannot go on for longer than the record 1164 tricks and 8344 cards.
Output format flexible.
Test cases
[Q--J----K--K-J---Q---A---A, ---K-K--JA-QA--J-----Q----] -> 712 tricks, 5104 cards
[K-KK----K-A-----JAA--Q--J-, ---Q---Q-J-----J------AQ--] -> 1007 tricks, 7157 cards
[---AK-Q--J----J--QKJ-Q----, ------JK-----A--K--Q---AA-] -> 1014 tricks, 7258 cards
[---AJ--Q---------QAKQJJ-QK, -----A----KJ-K--------A---] -> 1164 tricks, 8344 cards
You may find additional test cases and resources at this link
This is code-golf.