War - Puzzle Discussion

Are there any bugs?
For “One game, one battle” my number of rounds was 55, but testcase said, it is 52. When I submitted with 55 rounds, it showed, that my solution is correct… When I added condition like (when rounds == 55, print 52) it showed, that it is correct when submitted and even in testcase… WTF?
For “Long game”, the testcase shows, that the number of round should be 1262. When I correct my program, that it prints 1262 round, the testcase shows, that this solution is correct, but when I submit, the solution doesn’t work. Again, wtf?

Tests and validators are different, so your code can give different results. There are no bugs in the puzzle itself.

Allright, then I don’t understand conditions… what’s “one round”? When I start battle, it’s a new round, no? Except case, when I start WAR. Then it’s counted as one round, till someone wins, no? Where’s problem then?

A round is over when a winner is found for that round, no matter how many wars have taken place.

Thanks for reply, I solved it. I just don’t have it optimized enough to handle that long play.

1 Like

Hi, there is some problem with Test Case 5 “One Game, One Battle”, the test fails but the validator succeeded.

Have you checked why your code gives the wrong answer for Test case 5? Remember that the tests and the validators may be different.

Yes, it worked now, it was a mistake that caused the 5th test to fail but not the validator. It was the order of the cards after the war.

1 Like

Hello I passed each tests. However, I did not succeed with the validator 7 “long game”. I think it may be due to computation time but I am not sure. Is there a way to access to this validator 7 to understand why my code did not succeed? Thank you very much!

It should be stated that the cards that caused a war should also added to war cards in the explanation of the puzzle. There are some topics here that stated this problem. People are asking the same question.

That’s what i call “une petite boulette dans la traduction du sujet”

My french statement translation

the winner adds all the cards played during the round to their deck.

English statement

the winner adds all the cards from the "war" to their deck.

and that’s not a community puzzle that could be fixed easily…

You can put a print statement at the top of the code to access the starting hand for each player, and then copy and paste the rest of your code into a local python editor.

I know this because I’m stuck on the same test case and this is what I’m doing to debug.

I had the same issue now but even with following the rule my output went from 2 34 to 2 50. Anyone had a similar issue?

Would you please specify which case you have a problem with?

If you want, you may also upload your lists of both players’ cards at each step for that case to a website (e.g. Pastebin), so that I can compare my results with yours.

Hi :slight_smile:

there is something I don’t get it!
In the test 2, both players have 26 cards. There is no war so sometimes player 1 win rounds, sometimes player 2.
How can the exit be “2 26”
26 rounds for 26 cards means only one player win all the rounds
How is it possible?

Thanks :slight_smile:

If you pair up each card of Player 1 and each card of Player 2, you’ll see that Player 2 always has the higher card, so Player 2 wins all the rounds.

If you disagree, please list the first few rounds here for our checking.

Hey :slight_smile:
Thanks for you response!
I found my mistake.
I clean the values to change J,Q,K,A to numbers but I use slice(0,1) instead of slice(0,-1) (in JS)

Thanks :slight_smile:

1 Like

Greetings,
I have some questions regarding this puzzle. To simplify, let’s define the cards not used in fight during a war “Reserve” cards:

What is the sequence in which they should be added to the winners deck, should the “Reserve” cards be added first, or the “Fight” ones go first? Should they be added back to the deck in the same order they were removed?

What’s the logic behind PAT? Should PAT only occur when a player runs out of cards during a war?

Thank you

Q1

What is the sequence

The puzzle statement says:

for a “war”, all the cards from the first player then all the cards from the second player.

Q2

Should they be added back to the deck in the same order they were removed?

Yes.

Q3

What’s the logic behind PAT? Should PAT only occur when a player runs out of cards during a war?

The puzzle statement says:

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.

1 Like

Here are some hints:

  • Decks are FIFO, meaning the first card from console is also the top card (deck[0]);

  • There’s a Player 1 and a Player 2. The winning player always gets all the cards from Player 1 first, then Player 2, regardless of who wins or loses;

  • Each turn within a war round will remove 4 cards from each players deck: 3 will be put aside in a, let’s call it, “war deck”, and the last removed card will be used for battle. After the fight, the cards used for battle will be added to the bottom of the “war deck”. The winner of a war round wins both players “war decks”, first the “war deck” from Player 1, then Player 2.

  • The PAT rule applies when, during a war round, if a player runs out of cards while taking the first 3 cards for the “war deck”, it should then return “PAT”, instead of using the last card to battle.

Hope it becomes clearer