War - Puzzle Discussion

The description of the war is misleading. Thanks fo Xolott for clarifying.

The PAT rule is a bit strange, I agree. Running out of cards should result in losing.

I wonder if the game is fair or if one player is in advantage. After all, the rules are not fully symmetric.

Hi, I have some mistake on test 3, 5, and 7, but I don’t understand why (for the 3).

I create unit test for every case, and there are OK. So I create unit test for test 3 : all the 34 step I have, and I don’t undestand why the test 3 is make in 56 step and not in 34 step.

Can anyone help me find the error?

    class TestBataille(unittest.TestCase):
        def test_round_battle_step_1(self):
            cards1 = ['6H', '7H', '6C', 'QS', '7S', '8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
            cards2 = ['JH', 'AH', 'KD', 'AD', '9C', '2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H']
            expected1 = ['7H', '6C', 'QS', '7S', '8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
            expected2 = ['AH', 'KD', 'AD', '9C', '2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H']
            winner = round_battle(cards1, cards2)
            self.assertEqual(cards1, expected1)
            self.assertEqual(cards2, expected2)
            self.assertEqual(winner, 2)

        def test_round_battle_step_2(self):
            cards1 = ['7H', '6C', 'QS', '7S', '8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
            cards2 = ['AH', 'KD', 'AD', '9C', '2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H']
            expected1 = ['6C', 'QS', '7S', '8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
            expected2 = ['KD', 'AD', '9C', '2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H']
            winner = round_battle(cards1, cards2)
            self.assertEqual(cards1, expected1)
            self.assertEqual(cards2, expected2)
            self.assertEqual(winner, 2)

            def test_round_battle_step_3(self):
                cards1 = ['6C', 'QS', '7S', '8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
                cards2 = ['KD', 'AD', '9C', '2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H']
                expected1 = ['QS', '7S', '8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
                expected2 = ['AD', '9C', '2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C']

        def test_round_battle_step_4(self):
            cards1 = ['QS', '7S', '8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
            cards2 = ['AD', '9C', '2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C']
            expected1 = ['7S', '8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
            expected2 = ['9C', '2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS']

        def test_round_battle_step_5(self):
            cards1 = ['7S', '8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
            cards2 = ['9C', '2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS']
            expected1 = ['8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
            expected2 = ['2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S']

        def test_round_battle_step_6(self):
            cards1 = ['8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
            cards2 = ['2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S']
            expected1 = ['6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D']
            expected2 = ['2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S']

        def test_round_battle_step_7(self):
            cards1 = ['6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D']
            cards2 = ['2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S']
            expected1 = ['5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S']

        def test_round_battle_step_8(self):
            cards1 = ['5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S']
            expected1 = ['6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S']

        def test_round_battle_step_9(self):
            cards1 = ['6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S']
            expected1 = ['QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S']

        def test_round_battle_step_10(self):
            cards1 = ['QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S']
            expected1 = ['4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH']

        def test_round_battle_step_11(self):
            cards1 = ['4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH']
            expected1 = ['3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D']

        def test_round_battle_step_12(self):
            cards1 = ['3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D']
            expected1 = ['7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S']

        def test_round_battle_step_13(self):
            cards1 = ['7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S']
            expected1 = ['3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C']

        def test_round_battle_step_14(self):
            cards1 = ['3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C']
            expected1 = ['4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C']

        def test_round_battle_step_15(self):
            cards1 = ['4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C']
            expected1 = ['5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S']

        def test_round_battle_step_16(self):
            cards1 = ['5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S']
            expected1 = ['QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H']

        def test_round_battle_step_17(self):
            cards1 = ['QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H']
            expected1 = ['5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD']

        def test_round_battle_step_18(self):
            cards1 = ['5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD']
            expected1 = ['3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C']

        def test_round_battle_step_19(self):
            cards1 = ['3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C']
            expected1 = ['3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H']

        def test_round_battle_step_20(self):
            cards1 = ['3D', '8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['8S', '2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H']
            expected1 = ['8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            expected2 = ['2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D']

        def test_round_battle_step_21(self):
            cards1 = ['8C', '4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H']
            cards2 = ['2S', '10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D']
            expected1 = ['4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H', '8C', '2S']
            expected2 = ['10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D']

        def test_round_battle_step_22(self):
            cards1 = ['4H', '4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H', '8C', '2S']
            cards2 = ['10H', '8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D']
            expected1 = ['4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H', '8C', '2S']
            expected2 = ['8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H']

        def test_round_battle_step_23(self):
            cards1 = ['4C', 'QC', '5D', '7D', '8D', '2D', '6D', '2H', '8C', '2S']
            cards2 = ['8H', 'AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H']
            expected1 = ['QC', '5D', '7D', '8D', '2D', '6D', '2H', '8C', '2S']
            expected2 = ['AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C']

        def test_round_battle_step_24(self):
            cards1 = ['QC', '5D', '7D', '8D', '2D', '6D', '2H', '8C', '2S']
            cards2 = ['AC', '2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C']
            expected1 = ['5D', '7D', '8D', '2D', '6D', '2H', '8C', '2S']
            expected2 = ['2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC']

        def test_round_battle_step_25(self):
            cards1 = ['5D', '7D', '8D', '2D', '6D', '2H', '8C', '2S']
            cards2 = ['2C', '9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC']
            expected1 = ['7D', '8D', '2D', '6D', '2H', '8C', '2S', '5D', '2C']
            expected2 = ['9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC']

        def test_round_battle_step_26(self):
            cards1 = ['7D', '8D', '2D', '6D', '2H', '8C', '2S', '5D', '2C']
            cards2 = ['9H', 'JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC']
            expected1 = ['8D', '2D', '6D', '2H', '8C', '2S', '5D', '2C']
            expected2 = ['JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D']

        def test_round_battle_step_27(self):
            cards1 = ['8D', '2D', '6D', '2H', '8C', '2S', '5D', '2C']
            cards2 = ['JH', '6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D']
            expected1 = ['2D', '6D', '2H', '8C', '2S', '5D', '2C']
            expected2 = ['6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D']

        def test_round_battle_step_28(self):
            cards1 = ['2D', '6D', '2H', '8C', '2S', '5D', '2C']
            cards2 = ['6H', 'AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D']
            expected1 = ['6D', '2H', '8C', '2S', '5D', '2C']
            expected2 = ['AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D']
            winner = round_battle(cards1, cards2)
            self.assertEqual(cards1, expected1)
            self.assertEqual(cards2, expected2)
            self.assertEqual(winner, 2)

        def test_round_battle_step_29(self):
            cards1 = ['6D', '2H', '8C', '2S', '5D', '2C']
            cards2 = ['AH', '7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D']
            expected1 = ['2H', '8C', '2S', '5D', '2C']
            expected2 = ['7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D', 'AH', '6D']
            winner = round_battle(cards1, cards2)
            self.assertEqual(cards1, expected1)
            self.assertEqual(cards2, expected2)
            self.assertEqual(winner, 2)

        def test_round_battle_step_30(self):
            cards1 = ['2H', '8C', '2S', '5D', '2C']
            cards2 = ['7H', 'KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D', 'AH', '6D']
            expected1 = ['8C', '2S', '5D', '2C']
            expected2 = ['KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D', 'AH', '6D', '7H', '2H']
            winner = round_battle(cards1, cards2)
            self.assertEqual(cards1, expected1)
            self.assertEqual(cards2, expected2)
            self.assertEqual(winner, 2)

        def test_round_battle_step_31(self):
            cards1 = ['8C', '2S', '5D', '2C']
            cards2 = ['KD', '6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D', 'AH', '6D', '7H', '2H']
            expected1 = ['2S', '5D', '2C']
            expected2 = ['6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D', 'AH', '6D', '7H', '2H', 'KD', '8C']
            winner = round_battle(cards1, cards2)
            self.assertEqual(cards1, expected1)
            self.assertEqual(cards2, expected2)
            self.assertEqual(winner, 2)

        def test_round_battle_step_32(self):
            cards1 = ['2S', '5D', '2C']
            cards2 = ['6C', 'AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D', 'AH', '6D', '7H', '2H', 'KD', '8C']
            expected1 = ['5D', '2C']
            expected2 = ['AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D', 'AH', '6D', '7H', '2H', 'KD', '8C', '6C', '2S']
            winner = round_battle(cards1, cards2)
            self.assertEqual(cards1, expected1)
            self.assertEqual(cards2, expected2)
            self.assertEqual(winner, 2)

        def test_round_battle_step_33(self):
            cards1 = ['5D', '2C']
            cards2 = ['AD', 'QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D', 'AH', '6D', '7H', '2H', 'KD', '8C', '6C', '2S']
            expected1 = ['2C']
            expected2 = ['QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D', 'AH', '6D', '7H', '2H', 'KD', '8C', '6C', '2S', 'AD', '5D']
            winner = round_battle(cards1, cards2)
            self.assertEqual(cards1, expected1)
            self.assertEqual(cards2, expected2)
            self.assertEqual(winner, 2)

        def test_round_battle_step_34(self):
            cards1 = ['2C']
            cards2 = ['QS', '9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D', 'AH', '6D', '7H', '2H', 'KD', '8C', '6C', '2S', 'AD', '5D']
            expected1 = []
            expected2 = ['9C', '7S', 'JC', '5S', '10C', '6S', 'KC', 'QH', '10D', '4D', 'JS', '3S', 'JD', '7C', '9D', '3C', '9S', '4S', 'KS', '5H', 'AS', 'QD', 'KH', '5C', '10S', '3H', '8S', '3D', '10H', '4H', '8H', '4C', 'AC', 'QC', '9H', '7D', 'JH', '8D', '6H', '2D', 'AH', '6D', '7H', '2H', 'KD', '8C', '6C', '2S', 'AD', '5D', 'QS', '2C']
            winner = round_battle(cards1, cards2)
            self.assertEqual(cards1, expected1)
            self.assertEqual(cards2, expected2)
            self.assertEqual(winner, 2)

        def test_battle(self):
            cards1 = ['6H', '7H', '6C', 'QS', '7S', '8D', '6D', '5S', '6S', 'QH', '4D', '3S', '7C', '3C', '4S', '5H', 'QD', '5C', '3H', '3D', '8C', '4H', '4C', 'QC', '5D', '7D']
            cards2 = ['JH', 'AH', 'KD', 'AD', '9C', '2D', '2H', 'JC', '10C', 'KC', '10D', 'JS', 'JD', '9D', '9S', 'KS', 'AS', 'KH', '10S', '8S', '2S', '10H', '8H', 'AC', '2C', '9H']
            winner, number = battle(cards1, cards2)
            self.assertEqual(winner, 2)
            # /!\ The expected in codingame is 56
            self.assertEqual(number, 34)

You are not “putting” back the cards correctly

First the cards from the first player, then the one from the second player

So if game starts with
p1: 6H …
p2: JH …
Then p2 wins the round and puts the cards at the bottom of their deck in order 6H JH.
In your first test case the expected order is JH 6H

3 Likes

OK. So it’s always the card of first player and next the second player.

I misundestand this part of rules. For me it was first the card of winner, and next the card of loser of the round.

I will create new unit test. Thank you.

In test case 5, the expected result is “1 52” while my code compute it as “PAT” while doing test case. However, when I submit the code, it showed that test case 5 was actually correct… And the rule is even more confusing

1 Like

I had the same issue with 34 vs 56. Thanks a lot for clarifying.

1 Like

I had the same issue.

I assumed first player was referring to the player who came “first” (won) in the round. It seems weird that this part requires the arbitrary player number to be taken into account, when every other part of the game is independent of that fact, but I guess that’s just the rules.

Thanks for clarifying that part.

I find the rules very unclear.

For example, when winning a war, the 3 cards of the war go after the one in the battle? Okay, there is an example about this, but what about when are there several wars? We have fist card, 3 cards of the war, another card (still a tie), then all 3, and then the same for player 2?

And what if one player draws his last card? He loses immediately, or he has the chance on winning the battle, then surviving?

(BTW, also looks to me like the name of some test cases are wrong, speaking of “battles” when they should say “wars”)

i have the exact same problem with test case 5, that and test case 8 which also come up as correct when i submit my code…
but test case 7 fails when i submit

When you submit your code it is checked against validators which are different than visible test cases (although they should be similar).

Here’s test case 5 round by round. Hope it helps.

2 Likes

So now when doing the battle after the war P1 (and P2…) run out of cards. Shouldn’t this be a PAT situation?

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

Hello. I may have miss something but when I run my code I have an error. When I get with a join my deck and run my code in VS the code work perfectly. Somebody have this problem or now something that I’ve done wrong ?

The puzzle is working fine.
Problem must be in your code. What language are you using and what error are you getting?

1 Like

For anyone else stuck on long test only! I had this problem (I was timing out after 700,000+ rounds) and it turned out I had mapped Jack to 10 instead of 11! The other tests don’t have a J vs 10 match I guess.

1 Like

That was my problem. I was passing every single test expect for the long game where I had a tie on round 243 (I think). So glad you pointed this out ^^
I feel like it is not too bad to have always taking the cards of player 1 first, but at least it should say so in the statement, or even an example where player 2 wins a war would be enough…

But the statement does say so :slight_smile:

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

1 Like

Ups, you’re right. I blame the fact that is Friday and my brain is not on the best conditions :sweat_smile:

1 Like

hi, i have an issue with my code
in ide submission 5 & 7 fail, when i submit it, i reach 87% and only the “long game”
err : Le délai d’exécution du processus a été dépassé.
1 before 2 after battle is good
log of 2 battle chained:
Game Start
Cartes P1:[‘8C’, ‘KD’, ‘AH’, ‘QH’, ‘3D’, ‘KD’, ‘AH’, ‘QH’, ‘6D’]
Cartes P2:[‘8D’, ‘2D’, ‘3H’, ‘4D’, ‘3S’, ‘2D’, ‘3H’, ‘4D’, ‘7H’]
Bataille
Cartes B1:[‘8C’, ‘KD’, ‘AH’, ‘QH’]
Cartes B2:[‘8D’, ‘2D’, ‘3H’, ‘4D’]
Bataille
Cartes B1:[‘8C’, ‘KD’, ‘AH’, ‘QH’, ‘3D’, ‘KD’, ‘AH’, ‘QH’]
Cartes B2:[‘8D’, ‘2D’, ‘3H’, ‘4D’, ‘3S’, ‘2D’, ‘3H’, ‘4D’]
P2 gagne: 7H Vs 6D
Cartes P1:[]
Cartes P2:[‘8C’, ‘KD’, ‘AH’, ‘QH’, ‘3D’, ‘KD’, ‘AH’, ‘QH’, ‘6D’, ‘8D’, ‘2D’, ‘3H’, ‘4D’, ‘3S’, ‘2D’, ‘3H’, ‘4D’, ‘7H’]
Fin de Partie
Gagnant Joueur 2
2 1

all help are welcome, i use python
regards

Could it be any of your while loops never reaches the condition to break out of it?

i have only 1 loop