War - Puzzle Discussion

Salut

Je bloque aussi sur le test long, il me sort un PAT. Tout le reste passe niquel…

J’ai essayé un autre ordre pour ranger les cartes dans le cas du gagnant, comme proposé plus haut, à savoir pour les batailles enchaînées de ranger d’abord la bataille 1 (J1 + J2), puis la bataille 2 etc. Cette fois ci pas de PAT mais pas de réponse dans le temps imparti…

Help ! :grin:

Sinon je confirme selon moi que (si ça peut aider) :

  • Les cartes sont données comme un tas pret à jouer (la premiere qu’on obtient est celle à jouer)
  • Il faut remettre sous le tas toutes les cartes (dans l’ordre de leur sortie) du joueur1 et ensuite celles du joueur2, peut importe qui gagne la manche.

Hi

I’m also failing at the long test, I got PAT. All others work fine.

I tried another way to replace cards in case of chained War, as suggested here : first the first war (P1 and P2), then the second war and so on. This time I’ don’t get PAT but no answer in due time…

Help ! :grin:

For others I can say :

  • cards are given ready to play. The first card you receive is the one to play.
  • You have to put at the bottom the cards (in order of appearance) from player1 then player2, no matter who won.
2 Likes

well, thing is like this:
Player 1 : 10D 9S 8D KH 7D 5H 6S
Player 2 : 10H 7H 5C QC 2C 4H 6D
Step-1:
sub-step-1:
Player 1: 10D VS Player 2: 10H ; it`s a draw
sub-step-2: a war is happen
Player 1: 9S 8D KH (face down - which means no use, just take away)
Player 2: 7H 5C QC (face down - no use, take away)
sub-step-3: repeat a combat
Player 1: 7D VS Player 2: 2C ; Player 1 is winner, so all cards give to player 1
Step-1 result:
Player 1: 5H 6S 【10D 】【9S 8D KH】【 7D】 [10H] [7H 5C QC] [2C]
Player 2: 4H 6D

8 Likes

There’s a very simple mistake you can make, that is really hard to catch. If you’re only passing tests 1,4,6, and 9. Double check your substring logic. 10D has 3 characters contrary to the other 12 that only have 2.

And if you need help debugging the last two “PAT” tests:

  • Test 8 ends on round 89
  • Test 9 ends on round 56

One other bug I ran into that could be hard to catch:
This works:

    for (int c = 0,  pc1= FirstPlayer.PlayedCards.Count; c < pc1; c++)
    {
        player.Deck.Enqueue(FirstPlayer.PlayedCards.Dequeue());
    }

This does not:

    for (int c = 0; c < FirstPlayer.PlayedCards.Count; c++)
    {
        player.Deck.Enqueue(FirstPlayer.PlayedCards.Dequeue());
    }

I hope this helps.

1 Like

Also (especially if you failed in long games) need chek how you increment number of round. Only after winning fight (and if players has more than 0 cards).

Something that really helped me: every turn or war, check if the total amount of cards in play has changed. I found myself duplicating cards often… hope that helps someone…

@Tleilaxi thanks for that example! I’ve been going nuts.

I mistakenly interpreted “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).” as “all the cards from the winning player then all the cards from the losing player.”

I swapped the order I was adding cards back to the winning player so that the cards from player 1 always are added first and then the cards from player 2 are added, regardless of which player won, and suddenly all my failing tests were green!

1 Like

I did make same mistake. the rules should be more clear.
!!! Always cards of player number 1 are addedd to deck after battle/war first. it doesnt depend who did win !!!
I did lost half of the day with debuging :confused: all becasuse of unclear rules :confused:

1 Like

This is really important and should be highlighted in the challenge description.

1 Like

This is the current explanation in the english rules:

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

Do you have any suggestion to make it clearer?

Quand un joueur gagne une manche, il remet les cartes sous son tas dans un ordre précis. D’abord les cartes du premier joueur, puis celles du second joueur

Pourquoi doit on prendre les cartes du joueur 1 PUIS celles du joueur 2 ? Le plus logique serait qu’un joueur prenne d’abord ses cartes PUIS celles de l’adversaire !

Si on essaie de reproduire le jeu dans la réalité, il est absurde que quelqu’un se voit désigner Joueur 1 et l’autre Joueur 2 : tout le monde joue en même temps, il n’y a aucune raison que les joueurs doivent se différencier

Hello

I have a little problem.
I pass all test case and real case, exept long cases …

I don’t understand what is the problem, and I have no ideas to found the problem …

what is the normal number of sleeve for the long test of case ? Because, my counter stop to 576464 before the automatic stop for to long execussion time …

Thanks in advance for your answer, and for some ideas … if you have

Thanks, but I have found the solution alone … sorry for the useless question …

The War does not count as a turn.
Tie, War, Battle is all one turn.

Je suis d’accord que ce n’est pas conforme à la réalité. Je me suis fais avoir par cette règle. J’ai cherché pendant au moins deux heures avant de comprendre que c’était toujours le joueur 1.

1 Like

Can’t get the long game. I’ve gone through every card match up (330 of them) and war and the card counts and winners are correct therefore I think there is something wrong with my understanding of the rules on a double war puts cards back in the deck.

right now I have it doing the following:
Player 1 : 10D 8D KS 9H 5C 4D AD 7C JC
Player 2 : 10D AS 2H 4S 5D QH 6S KC QD

the 10’s would trigger a war, the 5’s would trigger a war and the Q would win so;

player 2 would get all of the cards from player 1 followed by all of the cards from player 2 as follows: 10D 8D KS 9H 5C 4D AD 7C JC 10D AS 2H 4S 5D QH 6S KC QD

is that correct?

1 Like

Yes, player 2 has got all the cards from player 1 and player 1 does not have any cards. Once that happens the game ends (player 2 has won the game) and you simply output that result.

Hello,

I have a problem on test 3, I found “2 34” and the result have to be “2 56”.
But I tried by hand and I found “2 34”, so I may misunderstand something but there is no war in this example !

Can someone help me ? Because tests on war and PAT works but not test which are easier !

Than you !

1 Like

did you try to find the answer in this thread? Most people had the same issue. I suggest searching here and also reading carefully the statement another time.

Some people give me the answer, I am just stupid, I thought you have to put card of the winner in first and not of the first player…

Sorry to disturb !

1 Like

Hello, I’m trying to solve a special test case (all of others test case passed), the “2 chained battle”. It expected the winner is 2 but I got PAT in my program.
So there is this two queue at the beginning :
[‘6D’, ‘3D’, ‘QH’, ‘AH’, ‘KD’, ‘8C’]
[‘7H’, ‘3S’, ‘4D’, ‘3H’, ‘2D’, ‘8D’]
So the first cards are 8 for both players, so a “war”, then the three next cards of their pile face down, and a new card which is 3 for both players and another battle, then the three next cards of their pile face down so both player runs out of cards during a war and it’s specify in the specific case : “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.” So it should be a draw because when giving up three cards both players runs out of card an it’s during a war, so my program print PAT but expected player 2 wins.
Do I miss something ?
Thank you
Sorry about my english.