# War - Puzzle Discussion

Hi, I had some problem understanding the rules.

The rule said that: If the two cards played are of equal value, then there is a âwarâ. First, both players place the three next cards of their pile face down. Then they go back to step 1 to decide who is going to win the war (several âwarsâ can be chained). As soon as a player wins a âwarâ, the winner adds all the cards from the âwarâ to their deck.

But, in the example:

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

They played the war with 4 cards each.
Player 1: 9S 8D KH 7D
Player 2: 7H 5C QC 2C

So, I need 3 o 4 cards in a War? O Iâm getting this wrong?

12 Likes

Hi

3 cards face down + 1 card face up (this is the step 1)

Je passe tous les tests, sauf 'un autre PAT".
En dĂ©taillant chaque pli, je nâaboutis effectivement pas dans une situation de âPATâ : le joueur 1 gagne aprĂšs 40 manches.

I pass all the tests, except âanother PATâ.
When I detail the battle I do not finish in a âPATâ situation : player 1 wins after 40 rounds.
Have I mist something ?

1 Like

Bonjour,
a priori jâai le meme probleme

It is easy to misunderstand the rules and hard to debug any discrepancies since you only get to compare the final results, anything can go wrong somewhere in between (unless there is some debug mode I am unaware of).

28 Likes

What is the order of the three cards face down during the battle ?
Are they put one after each other (the order of the cards is unchanged ) ?
Or are they put in one lot (the order is inverted) ?
Thank you.

Quel est lâordre des trois cartes Ă  dĂ©fausser lors dâune bataille ?
Sont-elles mises lâune aprĂšs lâautre (lâodre des cartes est inchangĂ©) ?
Merci.

4 Likes

I had a problem with both of the PAT tests and the mistake I did was that if one and only one player ran out of cards during a war - the other player won. This was apparently a PAT case, which is far from obvious. The quote: âThere are no winners in warâ does not fit this game

But frankly this doesnât sound like your problem, because you passed one of the PAT tests.

6 Likes

The order of the face down cards during a war is the same as they where in the main deck. The winner always takes the cards from player 1 first, no matter who won. Does it make sense?

5 Likes

I agree : in case only one player runs out of cards during a war shouldnât end up with a PAT. Still I did coded it right to have a PAT result for the eighth test.

I tried it with inverting the three faced down cards during a battle : I pass the last test âŠ but I get it wrong at the eighth one now !

2 Likes

Jâai finalement trouvĂ© mon erreur !
Je ne gĂ©rais pas le cas oĂč un joueur jpuais sa derniĂšre carte, mais remportait le pli.
Merci Ă  tous.

I found my mistake finally !
I wasnât managing when a player plays its last card, but can continue playing by winning the fold.
Thank you to all.

Je suis perdu: lorsque je valide mon code (les tests dâentrainement tous validĂ©s sauf le test long), je mâaperĂ§ois que tous les tests sont validĂ©s sauf le test long (jusque la rien dâaberrant) mais aussi le tout premier (âet Ă§a câest loucheâ comme dirait ma grand mĂšre).

Il doit donc y avoir un cas particulier qui me fait planter mais je nâarrive pas Ă  le recrĂ©er en jeu de test et je nâai pas le courage de regarder les 1200 et quelques manches du test âpartie longueâ. Quelquâun Ă  une idĂ©e pour me dĂ©bloquer?

merci

I am lost: Iâve sent a solution (beating every training tests but the âlong gameâ) and itâs validating the long test (nothing strange here) but also the first case (3 cards).

There must be a particular case I am not considering but I canât understand which one and I donât have the motivation to look the 1200 hands od the âlong gameâ test to understand my mistake. Anyone has an idea to unlock me?

Thanks

4 Likes

Bonjour LaFayette,

Jâai eu le mĂȘme problĂšme Ă  un certain moment. Pour ma part, câĂ©tait un problĂšme dâun mauvais calcul du nombre de coup jouĂ© total. Pour corriger ton algorithme, assure-toi que ton compteur de nombre de coup est bien efficace. Sinon assure-toi aussi de faire attention Ă  ce que tu mets dans les else (si tu les utilises).

Si ton premier test nâest pas valide je te conseille de corriger celui-ci en premier au lieu de la partie longue (gĂ©rer les erreurs sera plus facile).

JâespĂšre tâaider, si ton problĂšme persiste, dis-moi quand quel language tu code et jâessaierai de tâaider.
Bonne chance!

Yeah, I have the same problem that you two had. I donât think I messed up the counter because I got PAT for the âLong Gameâ test case. I also get 2 2138 on the first âPATâ case. If you or anyone got something similar, speak up!

Ouais, jâai le mĂȘme problĂšme que vous deux. Je ne pense pas que jâai gĂąchĂ© le compteur parce que jâai obtenu PAT pour le âLong Gameâ cas de test. Je reĂ§ois Ă©galement 2 2138 sur le premier cas âPATâ. Si vous ou quelquâun avez quelque chose de similaire, dites-le!

If anyone who works for CodinGame sees this, please edit the problem statement to make this a bit clearer.

I had been failing test cases 7 and 8 because of chained wars. The problem statement clearly says, âWhen a player wins a battle, they put back the cards at the bottom of their deck in a precise order. First the cards from the first player, then the one from the second player (for a âwarâ, all the cards from the first player then all the cards from the second player).â I interpreted this as, taking the cards from the p1 both wars, then from p2 in both wars. As you can see, the problem statement says ALL the cards from the first player, then the second.

If you change your code to give the players the cards from the first war, then the second war, and so on, it should work. Hopefully someone important sees this!

14 Likes

Hi, according to your comment â3 cards face down + 1 card face upâ and the example i have a question and maybe you can help me out.
These are the decks:
Player 1 : 10D 9S 8D KH 7D 5H 6S
Player 2 : 10H 7H 5C QC 2C 4H 6D

For Player One:
The 10D and 10H cause a war to happen so, the next three cards are â10D 9S 8Dâ or â9S 8D KHâ?? I am very confused.

So basically my question is, do you include the â10Dâ in the first 3 cards?

6 Likes

When the cards of the first and second player are equal ( == ), the battle start. When you start a battle, you got to remember that it is alway going the cards of the FIRST PLAYER that is going to be add in the deck of the winner, no matter which player wins the battle. Then, for the first player you take the first card (the one that start the battle), + the 3 next, then the next one is going to decide who wins the battle and this card is going to be add in the winnerâs deck too. In one single battle, 10 cards are going to move into the winnerâs deck and you got to be sure to follow the right orders (cards of first player then the cards of the second player)

Example:

First player: (10H<âstart the battle) (1H 2H 3H)<-- card for win 4H <âcard that fight 5H (other card)
Second player: 10D 1D 2D 3D 5D 6D
In this case, the winnin pack going to be 10H 1H 2H 3H 4H 10D 1D 2D 3D 5D.
The second player winâs the battle (5D > 4H)
The result is going to be only 5H for first player and 6D 10H 1H 2H 3H 4H 10D 1D 2D 3D 5D for the second player.

So, important, you have to remember (it is the same for a single fight), that when a player wins a fight or a battle, you got to alway put the card of the first player in the winnerâs deck and at the end of the list ( or arrays). This is wrriten in rules.

Good luck to you all, hope i help.
Like i said, if the problem is persitent show your code and im going to check what is wrong.

18 Likes

â9S 8D KHâ

I donât get it! What are the â1â cards?
They are not aces (already four aces in the game), but they seem to be superior to kingsâŠ

What are we supposed to do with them?

There is no 1 card in the game.