War - Puzzle Discussion

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
1 Like

Oups, indeed: despite reading the description several times, I read over the “special cases” section, my bad! :eyeglasses:
Thanks for the quick answer!

2 Likes

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.

:raised_hand_with_fingers_splayed: 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.

1 Like

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
2 Likes

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.

2 Likes

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

1 Like

No problem :slight_smile: