Read the statement again. N and M do not represent number of game turns.
== EDIT see below, i missed a section, the statement below is false (kept for history). ==
Agree with this: the problem should state what is the game situation in case of âhand is empty while in a warâ. For me, this situation should fall in the situation âa player wins if the other player has no cards left in its heapâ, but this is not what war tests expect.
@some moderator, could you please fix/precise the problem statement?
The statement has stated it, I donât think thereâs anything to fix?
If a player runs out of cards during a âwarâ (when giving up the three cards or when doing the battle), then the game ends and both players are placed equally first.
Output
If players are equally first: PAT
Oups, indeed: despite reading the description several times, I read over the âspecial casesâ section, my bad!
Thanks for the quick answer!
Thank you for your log! Thanks to you I could find that I was not adding the cards to my stack in the right order.
If it may help other coders:
At the end of a tour/round, I understood that Player 1 was adding his cards first then Player 2 cards BUT I believed that Player 2 was adding his card FIRST before adding Player 1 cards.
In fact, we always add to any stack, player 1 cards before player 2 cards, no difference.
To clear up some confusion. The card order when placing cards back into a playerâs deck matters. If itâs just a normal round, itâs player 1âs and then player 2âs cards. If itâs a war round, itâs all of player 1âs cards with the winning card at the end and then all of player 2âs cards with the loosing card at the end. IE
P1: ( 10 ) [ 2, 5, A ] ( J ) [ 9, K, Q ] 7
P2: ( 10 ) [ 9, 2, 4 ] ( J ) [ A, 3, 8 ] 4
Order: [ 10, 2, 5, A, J, 9, K, Q, 7, 10, 9, 2, 4, J, A, 3, 8, 4 ]
jâai un soucis, je passe tout les testes sauf 1: partie longue avec soumissions successives.
avec les logs, il est impossible de voir ce quâil se passe car on a pas tous les logs mais mon rĂ©sultat est diffĂ©rents:
Ăchec
Trouvé :1 1631
Attendu :2 1262
câest bon⊠jâai oubliĂ© de vider une liste
did you manage to solve the problem?
Hi, here are the correct rules (I have completed 100%):
- the cards order given in inputs is the order of play. For instance, if we have â5D 4H KSâ for player 1, then the first card player 1 will play is â5Dâ
- when both players have the same card value, you have to draw the NEXT 3 cards. For instance, player 1 has the following cards in order of play => â1D KH AS 8H 6Dâ and player 2 has the following cards in order of play "â1H 5D 4S JD 10Sâ. Then, player 1 plays â1Dâ. Player 2 plays â1Hâ. Both cards value are the same, itâs a battle. Player 1 draws âKH AS 8Hâ, Player 2 draws â5D 4S JDâ. After the battle, the next card played by player 1 is â6Dâ, the next one played by player 2 is â10Sâ. Player 2 wins that round
- when a player wins a round, he gets back all the played cards in his deck. No matter who is the player winning, the cards placed back in the deck are FIRST => all the cards played by player 1, in order. THEN => all the cards played by player 2 in order. So if you chained 2 battles in one round and both players had enough cards, then each player played 1 + 3 + 1 + 3 + 1 = 9 cards. The winner places 18 cards in his deck, the first 9 cards are from player 1, the next 9 nine cards are from player2, IN ALL CASES. The cards are placed in the winnerâs deck so that they will be the last to be played. The loser of the round lost his cards.
- Each round is the sum of actions that happened to decide the winner of the round. So if a round is comprised of a big chain of battles, it still counts as only one round. Consequently, the number of rounds is also the number of times a winning player puts back all the cards won in his deck.
- The game stops when one of the two players has no card left. In that case, you have to ouput the number of rounds and the winning player.
- The game also stops during a battle, when a player cannot draw enough cards. This rule has higher priority than the previous one. In that case, you have to output âPATâ, meaning nobody won
Salut,
Jâai pas de soucis, on finit bien sur un PAT, parce que P2 se retrouve Ă court de carte lors dâune bataille, lorsquâil faut dĂ©fausser ses 3 cartes.
ça arrive à la 57e manche.
Tu as peut ĂȘtre mal âremisâ les cartes des prĂ©cĂ©dentes manches.
Finally finished this puzzle! This one is not that difficult, just the instructions are missing some very important points.
Many people said it in this thread : when a player (be it player 1 or player 2) wins the round, he wins : all the played cards from player 1, then all the played cards from player 2 in this specific order (P1 then P2). This is different from a real world battle game where the winner of the round takes his played cards first, then the played cards from the loser.
What stuck me for 3 days though is another detail which is not said in the instructions : at the very beginning the cards from player 1 and player 2 are given as one block from the very top card on the deck to the very bottom card on the deck, i.e. the first one distributed will be the first one played.
In a real world battle game in the beginning, when distributing cards one by one, as a player each new card distributed goes at the top of your deck. In this game, you can imagine like each new card distributed goes at the very bottom of your deck. : the first one distributed will be the first one played
Whatâs vicious about this is, even if you mess the cards ordering (last distributed wrongly being first played) the â3 cardsâ and â26 cardsâ still pass. You can only detect that on the â2 successive warsâ test because with the wrong orders the expected successive wars do not happen.
Hope this helps you not to get stuck for days. The puzzleâs instructions really need to be updated.
I completed this in F#, which the language version is out of date currently, and Iâm not sure if you can beat it 100%. As far as I can tell, my logic is fully correct, and nothing Iâm doing is particularly slow, but it always times out on the long game. Has anyone beaten the Long Game in F#?
Yes. You may get an idea of the number of people who has solved the puzzle in F# and elected to publish their solutions here: https://www.codingame.com/training/medium/winamax-battle/solution (filter for F#).
Hello i hade the same problem. you have to return all the rounds played not only how many rounds the player win. player 2 win 41 round, player one win 15. 41 + 15 = 56
THANKS finally ! me and my GF understand why there is a mismatch for the count of rounds
THANKS!!!
I just find myself made same mistake ,and Iâm stuck for monthsâŠ
Thanks a lot, I was stuck for the exact same reason, and the exact same outcome (finding 2 & 34 instead of 2 & 56, and getting some gray hair about it)
Thank you very much for this comment, it helped me a lot to achieve this puzzle.
This was the part of the rules I did not understand well:
The winner places 18 cards in his deck, the first 9 cards are from player 1, the next 9 nine cards are from player2, IN ALL CASES
No problem