War - Puzzle Discussion

Yes there are: I can’t upload pictures (new user), but look at test 5, first card of the first player…

It’s “10”, not “1”.

2 Likes

AAAAHH Sorry, I only get the first char of each card (I don’t care about the color of the card)
I just forgot the “10” case…
Thanks!

4 Likes

Suddenly better! I didn’t get why I could’nt pass some tests… Here it is.

1 Like

I worked out that sometimes the string was like “10D”, but I was mapping J into 10, Q into 11, K into 12, and A into 13 when doing the comparisons. So, unfortunately, a 10 and a J were comparing as equal. Had to bump up J to 11, Q to 12, K to 13, and A to 14. Don’t make the same mistake.

4 Likes

Cant figure this out. It’s the 4th test case and seems to expect player 2 to win. Here’s my output.

``````> p1 cards 8C KD AH QH 2S
> p2 cards 8D 2D 3H 4D 3S
> 8C vs 8D
> p1Wins
> Added 8C KD AH QH 2S 8D 2D 3H 4D 3S to p1
> p1 now has 8C KD AH QH 2S 8D 2D 3H 4D 3S
> p2 now has
> Done: p1 8C KD AH QH 2S 8D 2D 3H 4D 3S p2
> 1 1
``````

Is the line “Added” is the final result or just the result after the first war?

It’s after the first war. But since p2 doesn’t have cards left at that point, the game is over. Only the last line in my previous comment is printed to the console.

I don’t see how p2 could be the winner

The first war makes player 1 win the three cards 8D, 2D and 3H.

I had to rewrite all my local variables as instance variables to not have out of memory error.

I think that something wrong in some testcases. I change the card into value(J=11, Q=12, K=13, A=14) for easier to calculate. Such as this test case:
Player1 ; 6H( 6) 7H( 7) 6C( 6) QS(12) 7S( 7) 8D( 8) 6D( 6) 5S( 5) 6S( 6) QH(12) 4D( 4) 3S( 3) 7C( 7) 3C( 3) 4S( 4) 5H( 5) QD(12) 5C( 5) 3H( 3) 3D( 3) 8C( 8) 4H( 4) 4C( 4) QC(12) 5D( 5) 7D( 7)

Player2 ; JH(11) AH(14) KD(13) AD(14) 9C( 9) 2D( 2) 2H( 2) JC(11) 10C(10) KC(13) 10D(10) JS(11) JD(11) 9D( 9) 9S( 9) KS(13) AS(14) KH(13) 10S(10) 8S( 8) 2S( 2) 10H(10) 8H( 8) AC(14) 2C( 2) 9H( 9)

My program solved this testcase as : 2 34 ,this answer is same as my manual calculation.
But the server’s answer is decided as : 2 56. Which one is true?

9 Likes

Nope. There is something wrong in your algorithm.

If you know your code is failing on a given test case anyway, you can always print out a load of debug info instead of worrying about printing out the results needed to pass the test. For example, print out your players’ decks after each round. The amount of info displayed will be truncated, but you can do multiple runs with different debug output enabled and so on.

1 Like

thanks, your explanation was good enough for me to solve this puzzle

Waaait a sec, do you mean this is supposed to be added in the order : the 4 p1 cards from war1, the 4 p2 cards from war1, the 4 p1 cards from war2, the 4 p2 cards from war2, and so on ?!
I thought it would be all p1 cards then all p2 cards, as you did. Is that not true ?..

3 Likes

I pass all the tests but long,submitting I pass all but long and Pat. Still not sure what I am missing to not pass these tests, any suggestions are greatly appreciated

Hey,

i had a little trouble, but now i think i understand the Rules,it works for all the Testcases, but not when i submit it! Can it be a coincidence that it works for the long Game with 1262 rounds and not when i submit it? Is there a possibility that we can get the Data for the Submitting exercise?

ok now i found out whats the problem have been, you have to be ready for a max of 3 WARs in de long games if everyone has the same problem like me

I had the same problem. Be carfeful to the vicious rule : you have to put the cards of the first player first (and not its cards) in the winning deck even when the second player win.

13 Likes

Had an issue for quite a while in there that had to do with dealing the cards.
The first card played is the first card that is dealt!

So when dealer gives you 2 3 4, you would play 2 3 4.
Not like in a “real” card game where 2 3 4 is played 4 3 2 from the top.

Ended up getting first test cases right, the other test cases showed the wrong turn number or were not solvable at all.

5 Likes