War - Puzzle Discussion

:card_box: Feel free to send your feedback or ask some help here! :card_box:

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.
Ai-je raté une subtilité ?

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).

26 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Ă©) ?
Ou les trois cartes sont-elles mises groupĂ©es (l’ordre est inversĂ©) ?
Merci.

3 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 :stuck_out_tongue_winking_eye:

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.