# War (puzzle): order of cards

@DjordjeMicakovic This drove me crazy,they could have simply put some nice symetric rules for us

1 Like

Thank you for this. I was also going crazy over this. Guess I should have read the rules more carefully and not assumed how it worked. I think if they had player 2 win in the example, it would do a better job of showing that you always return player 1âs card first.

Me too guys that is the reason why i explain this

I 've issue with test 07.
I put all cars on a String value and i replace the 10 card by letter T (like Ten)
Supposed that player1 has 456QJ827JJ6KQ925968A42278AT
and player 2 has 463KJTA5KT9985A34K73QT37Q
I donât understand really the order of cards during a battle and many wars.

What is expected cards values of each player after this battle ?

Many Thanks

thanks a lot âŚ this helped
i was having the same 34 rounds problem and it was driving me crazy

Read carefully how the cards are given on top of the winnerâs deck.

Thanks to everyone who posted here and helped clear up the rules. I was confused for a long time, and the info here helped me to figure out how this was supposed to work. Just to help consolidate it all, hereâs how it works:

1. The FIRST card in the input for each player, is the âtopâ of their deck. So if the input reads â10D 9S 8D KH 7D 5H 6Sâ, the player will draw â10Dâ on their first round.

2. The only way to win, is to take the other playerâs last card during the first battle in a round, i.e. before any wars in that round. If a player runs out of cards at any other point (i.e. during a war or a warâs battle) itâs a PAT.

3. Each round, all the cards played by player 1 go into a pile with the first card on âtopâ, and each subsequent card added beneath. Likewise, the cards for player 2 go into a similar, separate pile. So the top of one of these piles is the card from the initial battle. Then the three cards from the first war, then the card from that warâs battle, etc.

4. Regardless of which player wins a round, the player 1 pile is added to the bottom of the winnerâs deck first, then the player 2 pile. Yes, this is asymmetrical.

3 Likes

Hi there,

every test-case containing a war fails and I think that itâs because I donât get the example right.

In my opinion there is an error in there (and maybe I am wrong about this and thatâs why it fails):

For example, if the card distribution is the following:
Player 1 : 10D 9S 8D KH 7D 5H 6S
Player 2 : 10H 7H 5C QC 2C 4H 6D
Then after one game turn, it will be:
Player 1 : 5H 6S 10D 9S 8D KH 7D 10H 7H 5C QC 2C
Player 2 : 4H 6D

If I do this by hand I would do the following:

1. Battle top cards (10D <=> 10H)
2. Start war because they are equal
3. compare 9S <=> 7H --> Player 1 wins
4. compare 8D <=> 5C -> P1 wins
5. compare KH <=> QC -> P1 wins
6. check how often Player 1 and Player 2 won
7. Player 1 one because of a win-rate 3:0
8. Add cards of P1 (1-4) to the end (bottom) of the deck of P1 => 7D 5H 6S 10D 9S 8D KH
9. Add the cards of P2 (1-4) to deck of P1, too: => 7D 5H 6S 10D 9S 8D KH 10H 7H 5C QC
=> Round one ended with Player 1 as winner for that round

Player 1 : 7D 5H 6S 10D 9S 8D KH 10H 7H 5C QC
Player 2 : 2C 4H 6D

So I noticed that the example puts the next card (that should come after the war, which should be round 2) of both Player 1 and Player 2 to the deck of Player one, too. I donât get why because the rules say, that one adds all the war-cards. These should just include the first card (where both have the same value) and the 3 cards of the war (9S 8D KH <=> 7H 5C QC).

Is the example wrong or is it me? Any suggestions appreciated.

The three cards that get put aside (as loot) donât participate in the war. The third step is: compare 7D and 2C.

So we just put 3 cards aside but one single war is just about one card (if not extended because the compared cards are equal)?

Maybe the special case confused me here:

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.

You always compare just two cards to decide a battle/war.

Ok, thank you soo much! It now works like a charm!
I totally got it wrong because I thought we should compare all three cards to see who has more high-cards.

thankâs, it took me a lot of time

I, for one, find Winamaxâs puzzle goal statement to be quite unclear from programmers point of view. My code has passed three (3) first tests just fine but Iâm struggling with test 04, the first battle. I thought I had understood the instructions correctly but apparentlyâŚ I havenât. Since hereâs quite a few guys/gals who have solved this, could anyone point out (the obvious) reason why test 04 is not passing?

Hereâs meh console output.

``````Console output
Standard Output Stream:

game commencing
deck1 contains 8C KD AH QH 2S
deck1 contains 8D 2D 3H 4D 3S
round reset
deck1 has 5 cards
deck2 has 5 cards
deck1 plays 8C
deck2 plays 8D
round tied, war begins
deck1 plays KD
deck1 plays AH
deck1 plays QH
deck2 plays 2D
deck2 plays 3H
deck2 plays 4D
deck1 won round
deck1 received 8 cards 8C KD AH QH 8D 2D 3H 4D
round reset
deck1 has 9 cards
deck2 has 1 cards
deck1 plays 2S
deck2 plays 3S
deck2 won round
deck2 received 2 cards 2S 3S
round reset
deck1 has 8 cards
deck2 has 2 cards
deck1 plays 8C
deck2 plays 2S
deck1 won round
deck1 received 2 cards 8C 2S
round reset
deck1 has 9 cards
deck2 has 1 cards
deck1 plays KD
deck2 plays 3S
deck1 won round
deck1 received 2 cards KD 3S

1 4

Failure
Found:  1
Expected:  2
``````

Thanx

pffffâŚ this was driving me crazy too!!

Yeah because itâs completely counterintuitive, why would the players behave differently when they win a battle ? This doesnât make much senseâŚ
I somehow knew I had to read and read again the instructions, as the bug was most likely located there.

hey, maybe i m late but your problem is how you handle a war:
in your example, you compare the first card of each deck (numberOfTheDeck.numberOfTheCards) :

• 1.1 = 8 and 2.1 = 8 so 1.1 = 1.2 -> letâs begin a war !!
• in the rules (and you know that if you have play once the war game), each player give up 3 cards.
• so now to know who won the war we have to compare 1.(1+3) and 2.(1+3).
1.4 = 2 and 2.4 = 3 so 2.4 > 1.4 -> player 2 won !!
• he won the war so he take the cards 1.1, 1.2, 1.3, 1.4, 2.1, 2.2, 2.3, 2.4. player 1 have no cards left so player 2 won.