War - Puzzle Discussion

I’m not sure what’s wrong with your input, but each player has 9 cards in that test case, not 6.
P1 has: 8C, KD, AH, QH, 3D, KD, AH, QH, 6D
P2 has: 8D, 2D, 3H, 4D, 3S, 2D, 3H, 4D, 7H

8C vs. 8D: WAR
8C, KD, AH, QH and 8D, 2D, 3H, 4D go to each “war deck”
Next they draw: 3D, 3S: WAR
3D, KD, AH, QH and 3S, 2D, 3H, 4D go to each “war deck”
Next they draw: 6D, 7H: Player 2 wins and gets everything.

Maybe there is something wrong when you read the input?

Edit: Looks like all cards which go into the war deck are duplicates. Do you possibly have a unique check somewhere?

Wow… Come on !! Thank you Garrincha !!

you are probably dealing the card in the opposite order

Not as useless as you might think !
What was your problem? Because I probably have the same.

I was confused by this game, because I did not return the 3 cards one by one (making things complex for realistic when the algo is simple).
It would have been better with clear examples :wink:

Thanks! I’ve had a problem like that a few years ago… A shame I didn’t remember that. You got me to 100%! :tada:

solved 100%, but too long to debug. The difficulty should be in the problem, not in long data to read and deal with truncated debug info if there are too many rows.

> p1 cards 8C KD AH QH **2S**
> p2 cards 8D 2D 3H 4D **3S**
> 8C vs 8D
> p1Wins

You code should conclude that P2 wins (3>2)

Thank you, you saved me.

I misread the given explanation and added the cards of the winning player first (like it is with most games of that type I know).

I even went through the faulty case by hand and arrived at the same solution (as I added winning player first again).

Stupid head replacing “first player” with “winning player”.

Anyway, thanks. Now I can go to sleep :smiley:

Here is something I have learned. You can play the cards in the reverse order and some test cases will pass. You can put cards from a War into the deck in the wrong order and still pass many of the tests.

So just because many of the tests pass does not mean you are moving cards around in the correct order.

1 Like

It literally says that you add cards to the top of the deck, but that is clearly not the case.

I have no clue about this puzzle. How do the wars work? In what order are the cards from each player added into the deck? I have so many questions! The rules of this puzzle are so vague.

“Cards are placed face down on top of each deck.” does not mean “cards are placed on the top of each deck face down”.

The cards are given in the order they will be played.

Yet more confusion from this puzzle’s description:

“Special cases:
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.”

“Victory Conditions
A player wins when the other player no longer has cards in their deck.”

Direct contradiction.

I realize you’re playing on words, but still don’t see any contradiction between just the two snippets you quote.

One describes the draw situation. One describes the victory/defeat situation.

What’s wrong, in more detail?

I am not playing on words. I am reading them literally.
The one describing the victory condition says "A player wins when the other player no longer has cards in their deck.”

That is only part of the victory condition, because if that happens during a war, then “both players are placed equally first” which I suppose means a draw. A draw is not victory.

Correct would be “A player wins when the other player runs out of cards outside of a war.” or “A player wins when the other player runs out of cards after playing the first card of the round.”

This is not a play on words. This is literally what it says. Please don’t take it personally.

If a player runs out of cards while placing the 3 face down after a matching pair, does the player lose or is it a draw?

Just interpret “Special Case” as superseding the rest. It’s an exception, identified as such.

As for me, I’ve figured this out (finally). I’m just saying it would take a minimum of effort for a couple of minutes to reword it, and would seem to be the duty of the creator. This “special case” is not shown in the short example.

Good job!

I’ll concede this isn’t the best worded puzzle on CG. Possibly they’d take your suggestions, too.

But you might want to realize that as far as example and tests go, it’s got all you can ask for: the special case seems to be explicitly verified in one of the explicit PAT cases, and the statenemt couldn’t possibly demonstrate all ending types in a single example.

So not sure if anyone else did this but I think I saw a comment above mention it. I was tallying the amount of times each player one and was using that to determine who was winning when I should have just checked while player had no cards left. This left me getting the result 1 1262 for the Long game vs 2 1262. Just thought i’d put that out there in case anyone else experienced this too

1 Like