War - Puzzle Discussion


#108

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?


#110

Wow… Come on !! Thank you Garrincha !!


#111

you are probably dealing the card in the opposite order


#112

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


#114

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:


#115

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:


#116

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.


#117
> 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)


#118

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:


#119

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.


#120

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


#121

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.


#122

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


#123

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.


#124

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?


#125

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?


#126

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


#127

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.


#128

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.