<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="279610" data-post-id="279610">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sodapopcan" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sodapopcan/120/34668_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sodapopcan
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Based on actually playing War as a kid on boring school trips this tracks.  We’d often get frustrated and resort to “mega wars” where we would put 3 cards face down in the event of a tie just to try and make the game end <img src="https://forum.elixirforum.com/images/emoji/apple/sweat_smile.png?v=15" title=":sweat_smile:" class="emoji" alt=":sweat_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="279610" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/trying-to-implement-war-card-game-in-elixir/54134/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-279610" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="279610"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="279617" data-post-id="279617">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zoedsoupe" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zoedsoupe/120/25602_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zoedsoupe
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yes, that true… The problem is that the game description does not cover any draw state, only turn winners  so I imagine that the first player to run out of cards will be ever the loser, considering those tests cases…</p>
<p>This is the complete assign description:</p>
<p>Preamble</p>
<blockquote>
<p>In this project, you will simulate a game of War. War is a simple card game between two players. A description of the game and its rules can be found here:<br>
<a href="https://bicyclecards.com/how-to-play/war" class="inline-onebox" rel="noopener nofollow ugc">War</a><br>
Given the above description, there are still some situations that are ambiguous. They will be clarified in the game description below.<br>
You will complete this project in three of the four languages we study in this course. The languages chosen are up to you. In addition to the general requirements of the project, each language comes with its own language-specific constraints. These specify the format of the input and output, as well as submission instructions for each language.<br>
Aside from these requirements, anything you do inside your program is up to you. Use as many helper functions or methods as you want, use any syntax you find useful whether we covered it in class or not. There is one exception to this: you may not use any functionality that is not part of the base installation of each language. No 3rd party libraries. Your submission will be tested using out-of-the-box installations of each language.</p>
</blockquote>
<p>Game description</p>
<blockquote>
<p>The game starts with a shuffled deck of cards. The deck will be passed into your program already shuffled (details below). The cards are dealt in an alternating fashion to each player, so that each player has 26 cards.<br>
In each round, both players reveal the top card of their pile. The player with the higher card (by rank) wins both cards, placing them at the bottom of their pile. Aces are considered high, meaning the card ranks in ascending order are 2-10, Jack, Queen, King, Ace.<br>
If the revealed cards are tied, there is war! Each player turns up one card face down followed by one card face up. The player with the higher face-up card takes both piles (six cards – the two original cards that were tied, plus the four cards from the war). If the turned-up cards are again the same rank, each player places another card face down and turns another card face up. The player with the higher card takes all 10 cards, and so on.<br>
When one player runs out of cards, they are the loser, and the other the winner. If, during a war, a player runs out of cards, this counts as a loss as well.</p>
</blockquote>
<p>Technical details:</p>
<blockquote>
<p>Input: The input to your program, representing a shuffled deck of cards, will be a permutation of 52 integers, where each integer between 1-13 occurs four times. The integers in this permutation correspond to cards according to the following table (four kings, four tens, four threes, and so on). Notice that we don’t bother representing the suit because the game of War doesn’t require it.<br>
The game: Your program will deal two piles from the input permutation. How you represent your piles is completely up to you. Once the piles are dealt, “play” the game in your program until one player runs out of cards. Once again, how you manage your piles during the game is completely up to you. Keep going until one player runs out of cards.<br>
When cards are added to the bottom of a player’s pile, they should be added in decreasing order by rank. That is, first place the highest ranked card on the bottom, then place the next highest ranked card beneath that. This is true of wars as well. If a player wins six cards as a result of a war, those cards should be added to the bottom starting with the highest rank and ending with the smallest. Ace has the highest rank, Two has the lowest.<br>
Output: Your program will return the pile of the winning player. This pile should contain all 52 integers from the original input permutation and be in the correct order according to how the game played out.</p>
</blockquote> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="279617" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/trying-to-implement-war-card-game-in-elixir/54134/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-279617" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="279617"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="279619" data-post-id="279619">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zoedsoupe" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zoedsoupe/120/25602_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zoedsoupe
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Oh i was getting infinite loop because I was throwing away the state of the turn loser… Now we get back to state 0, test cases fails with little differences and I still didn’t get what is happening</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  1) test War deal_1 (WarTest)
     test/war_test.exs:5
     Assertion with == failed
     code:  assert War.deal(t1) == r1
     left:  [
              1,
              13,
              13,
              13,
              13,
              12,
              12,
              12,
              12,
              11,
              11,
              11,
              11,
              10,
              10,
              10,
              10,
              9,
              9,
              9,
              9,
              8,
              8,
              8,
              8,
              7,
              7,
              7,
              7,
              6,
              6,
              6,
              6,
              5,
              5,
              5,
              5,
              4,
              4,
              4,
              4,
              3,
              3,
              3,
              2,
              2,
              1,
              3,
              1,
              2,
              1,
              2
            ]
     right: [
              1,
              1,
              1,
              1,
              13,
              13,
              13,
              13,
              12,
              12,
              12,
              12,
              11,
              11,
              11,
              11,
              10,
              10,
              10,
              10,
              9,
              9,
              9,
              9,
              8,
              8,
              8,
              8,
              7,
              7,
              7,
              7,
              6,
              6,
              6,
              6,
              5,
              5,
              5,
              5,
              4,
              4,
              4,
              4,
              3,
              3,
              3,
              3,
              2,
              2,
              2,
              2
            ]
     stacktrace:
       test/war_test.exs:8: (test)



  2) test War deal_4 (WarTest)
     test/war_test.exs:23
     Assertion with == failed
     code:  assert War.deal(t4) == r4
     left:  [
              1,
              1,
              1,
              13,
              13,
              13,
              13,
              12,
              12,
              12,
              12,
              11,
              11,
              11,
              11,
              10,
              10,
              10,
              10,
              9,
              9,
              9,
              8,
              8,
              8,
              8,
              7,
              7,
              7,
              7,
              6,
              6,
              6,
              6,
              5,
              5,
              5,
              5,
              4,
              4,
              4,
              4,
              3,
              3,
              3,
              3,
              2,
              2,
              2,
              2,
              1,
              9
            ]
     right: [
              1,
              1,
              13,
              12,
              9,
              5,
              11,
              4,
              9,
              3,
              8,
              7,
              7,
              2,
              13,
              10,
              12,
              5,
              10,
              4,
              9,
              6,
              8,
              3,
              1,
              1,
              13,
              12,
              7,
              5,
              11,
              4,
              9,
              3,
              8,
              6,
              7,
              2,
              13,
              10,
              12,
              5,
              11,
              11,
              10,
              8,
              6,
              4,
              6,
              3,
              2,
              2
            ]
     stacktrace:
       test/war_test.exs:26: (test)



  3) test War deal_2 (WarTest)
     test/war_test.exs:11
     Assertion with == failed
     code:  assert War.deal(t2) == r2
     left:  [
              1,
              1,
              1,
              13,
              13,
              13,
              13,
              12,
              12,
              12,
              12,
              11,
              11,
              11,
              11,
              10,
              10,
              10,
              10,
              9,
              9,
              9,
              9,
              8,
              8,
              8,
              8,
              7,
              7,
              7,
              7,
              6,
              6,
              6,
              6,
              5,
              5,
              5,
              5,
              4,
              4,
              4,
              4,
              3,
              3,
              3,
              3,
              2,
              2,
              2,
              1,
              2
            ]
     right: [
              4,
              3,
              2,
              2,
              2,
              2,
              4,
              3,
              4,
              3,
              4,
              3,
              6,
              5,
              6,
              5,
              6,
              5,
              6,
              5,
              8,
              7,
              8,
              7,
              8,
              7,
              8,
              7,
              10,
              9,
              10,
              9,
              10,
              9,
              10,
              9,
              12,
              11,
              12,
              11,
              12,
              11,
              12,
              11,
              1,
              13,
              1,
              13,
              1,
              13,
              1,
              13
            ]
     stacktrace:
       test/war_test.exs:14: (test)

..

  4) test War deal_3 (WarTest)
     test/war_test.exs:17
     Assertion with == failed
     code:  assert War.deal(t3) == r3
     left:  [
              1,
              1,
              1,
              13,
              13,
              13,
              13,
              12,
              12,
              12,
              12,
              11,
              11,
              11,
              11,
              10,
              10,
              10,
              10,
              9,
              9,
              9,
              9,
              8,
              8,
              8,
              8,
              7,
              7,
              7,
              7,
              6,
              6,
              6,
              6,
              5,
              5,
              5,
              5,
              4,
              4,
              4,
              4,
              3,
              3,
              3,
              3,
              2,
              2,
              2,
              1,
              2
            ]
     right: [
              4,
              3,
              2,
              2,
              2,
              2,
              4,
              3,
              4,
              3,
              4,
              3,
              6,
              5,
              6,
              5,
              6,
              5,
              6,
              5,
              8,
              7,
              8,
              7,
              8,
              7,
              8,
              7,
              10,
              9,
              10,
              9,
              10,
              9,
              10,
              9,
              12,
              11,
              12,
              11,
              12,
              11,
              12,
              11,
              1,
              13,
              1,
              13,
              1,
              13,
              1,
              13
            ]
     stacktrace:
       test/war_test.exs:20: (test)



  5) test War deal_5 (WarTest)
     test/war_test.exs:29
     Assertion with == failed
     code:  assert War.deal(t5) == r5
     left:  [
              1,
              1,
              1,
              13,
              13,
              13,
              13,
              12,
              12,
              12,
              11,
              11,
              11,
              11,
              10,
              10,
              10,
              10,
              9,
              9,
              9,
              9,
              8,
              8,
              8,
              8,
              7,
              7,
              7,
              7,
              6,
              6,
              6,
              6,
              5,
              5,
              5,
              5,
              4,
              4,
              4,
              4,
              3,
              3,
              3,
              3,
              2,
              2,
              2,
              2,
              1,
              12
            ]
     right: [
              1,
              10,
              13,
              8,
              11,
              9,
              8,
              7,
              11,
              8,
              13,
              7,
              13,
              6,
              12,
              6,
              9,
              5,
              8,
              5,
              7,
              4,
              7,
              4,
              11,
              6,
              12,
              10,
              6,
              3,
              2,
              2,
              12,
              5,
              9,
              3,
              10,
              4,
              9,
              2,
              10,
              3,
              5,
              2,
              1,
              1,
              1,
              13,
              12,
              11,
              4,
              3
            ]
     stacktrace:
       test/war_test.exs:32: (test)


Finished in 0.09 seconds (0.00s async, 0.09s sync)
18 tests, 5 failures
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="279619" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/trying-to-implement-war-card-game-in-elixir/54134/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-279619" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="279619"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="279621" data-post-id="279621">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Sebb" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Sebb/120/21818_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Sebb
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="zoedsoupe" data-post="13" data-topic="54134">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zoedsoupe/48/25602_2.png" class="avatar"> zoedsoupe:</div>
<blockquote>
<p>When cards are added to the bottom of a player’s pile, they should be added in decreasing order by rank.</p>
</blockquote>
</aside>
<p>This may avoid a loop.<br>
I think a draw will still be possible, so the assignment is not complete…?</p>
<aside class="quote no-group" data-username="zoedsoupe" data-post="13" data-topic="54134">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zoedsoupe/48/25602_2.png" class="avatar"> zoedsoupe:</div>
<blockquote>
<p>Aside from these requirements, anything you do inside your program is up to you.</p>
</blockquote>
</aside>
<p>Do you use the Queue on purpose? This could be solved in a simpler way with just two lists and a recursion.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="279621" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/trying-to-implement-war-card-game-in-elixir/54134/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-279621" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="279621"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="279622" data-post-id="279622">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="soup" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/soup/120/31425_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  soup
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I would manually play some hands with a smaller deck to verify and use those as your initial tests, as parsing out those 52 card stacks can be obtuse.</p>
<p>I also wondered about your <code>able_to_war?</code> check, if you read the end of the game description, I think it hints at another interpretation. The winner will be the same, but the cards in the final hand would be different. Truly only guessing though.</p>
<details>
<summary>
spoiler</summary>
<p>“If, during a war, a player runs out of cards, this counts as a loss as well.”</p>
<p>Meaning play to exhaustion, instead of giving up if you have less than 3 cards? Maybe? I’ve never played the real game.</p>
</details> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="279622" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/trying-to-implement-war-card-game-in-elixir/54134/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-279622" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="279622"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="279623" data-post-id="279623">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zoedsoupe" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zoedsoupe/120/25602_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zoedsoupe
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Sebb" data-post="15" data-topic="54134">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sebb/48/21818_2.png" class="avatar"> Sebb:</div>
<blockquote>
<p>I think a draw will still be possible, so the assignment is not complete…?</p>
</blockquote>
</aside>
<p>I really don’t know! actually, I’m doing this assignment as a freelancer job so I don’t have direct access to whom wrote the assignment</p>
<aside class="quote no-group" data-username="Sebb" data-post="15" data-topic="54134">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sebb/48/21818_2.png" class="avatar"> Sebb:</div>
<blockquote>
<p>Do you use the Queue on purpose? This could be solved in a simpler way with just two lists and a recursion.</p>
</blockquote>
</aside>
<p>I used a Queue to simplify war implementation, so that wouldn’t have so many <code>++/2</code> and <code>[x | xs]</code> in the whole program. i thought it would be simpler to manage state via a Queue</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="279623" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/trying-to-implement-war-card-game-in-elixir/54134/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-279623" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="279623"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="279624" data-post-id="279624">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zoedsoupe" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zoedsoupe/120/25602_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zoedsoupe
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yeah, i’ll try to run manually or via debugger with smaller decks…</p>
<aside class="quote no-group" data-username="soup" data-post="16" data-topic="54134">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/soup/48/31425_2.png" class="avatar"> soup:</div>
<blockquote>
<p>I also wondered about your <code>able_to_war?</code> check, if you read the end of the game description, I think it hints at another interpretation.</p>
</blockquote>
</aside>
<p>Hmmm <img src="https://forum.elixirforum.com/images/emoji/apple/thinking.png?v=15" title=":thinking:" class="emoji" alt=":thinking:" loading="lazy" width="20" height="20"> I don’t know, I’m confused at this time haha, I’ll try it too</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="279624" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/trying-to-implement-war-card-game-in-elixir/54134/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-279624" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="279624"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="279629" data-post-id="279629">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zoedsoupe" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zoedsoupe/120/25602_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zoedsoupe
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>take a look at <a href="https://github.com/bstakes/war-cardgame" rel="noopener nofollow ugc">github.com/bstakes/war-cardgame</a> or <a href="https://github.com/Bovojon/BlackJack-War-Games/blob/master/aabdul15_mashres15_war.hs" rel="noopener nofollow ugc">github.com/Bovojon/BlackJack-War-Games/blob/master</a>. both fails for tests cases so I imagine these test cases are wrong or some rule is missing</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="279629" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/trying-to-implement-war-card-game-in-elixir/54134/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-279629" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="279629"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="279633" data-post-id="279633">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Sebb" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Sebb/120/21818_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Sebb
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="zoedsoupe" data-post="17" data-topic="54134">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zoedsoupe/48/25602_2.png" class="avatar"> zoedsoupe:</div>
<blockquote>
<p>I’m doing this assignment as a freelancer job so I don’t have direct access</p>
</blockquote>
</aside>
<p>so its not homework. Then I can do this. Its probably not correct anyway. Or the sorting rule is not fair.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule WarTest do
  use ExUnit.Case

  import Enum
  import War

  test "test" do
    assert :player_1 == play({[4, 4, 3, 3], [1, 1, 2, 2]})
    assert :player_1 == play({[4, 4, 1, 1], [2, 2, 3, 3]})
    assert :player_2 == play({[4, 3, 2, 1], [4, 4, 3, 3]})
    assert :player_2 == play({[2, 2, 3, 3], [4, 4, 1, 1]})
    assert :draw == play({[1, 2], [2, 1]})
    assert :draw == play({[1, 2], [1, 2]})
    assert :draw == play({[2, 1], [2, 1]})

    n_runs = 100_00
    %{player_1: player_1_wins} = 1..n_runs |&gt; map(fn _ -&gt; deal() |&gt; play() end) |&gt; frequencies()
    assert player_1_wins / (n_runs / 2) - 1 &lt; 0.01
  end
end

defmodule War do
  import Enum

  @trace false

  def play(decks) do
    round_(:normal, decks, [])
  end

  defp round_(state, {deck_1, deck_2}, pot) do
    if @trace, do: dbg({state, {deck_1, deck_2}, pot})
    round(state, {deck_1, deck_2}, pot)
  end

  defp round(_, {[], []}, _), do: :draw
  defp round(_, {_, []}, _), do: :player_1
  defp round(_, {[], _}, _), do: :player_2

  defp round(:war, {[c, c1 | d1], [c, c2 | d2]}, pot) do
    round_(:war, {d1, d2}, pot ++ [c, c1, c, c2])
  end

  defp round(:war, {[c11, c12 | d1], [c21, c22 | d2]}, pot) do
    round_(:normal, decks(c11, c21, d1, d2, pot ++ [c11, c12, c21, c22]), [])
  end

  defp round(_, {[c | d1], [c | d2]}, pot) do
    round_(:war, {d1, d2}, pot ++ [c, c])
  end

  defp round(_, {[c1 | d1], [c2 | d2]}, pot) do
    round_(:normal, decks(c1, c2, d1, d2, [c1, c2]), pot)
  end

  defp decks(c1, c2, d1, d2, pot) do
    pot = sort(pot, :desc)
    if c1 &gt; c2, do: {d1 ++ pot, d2}, else: {d1, d2 ++ pot}
  end

  @set_of_cards to_list(2..14)
  defp deal(set_of_cards \\ @set_of_cards) do
    set_of_cards
    |&gt; List.duplicate(4)
    |&gt; List.flatten()
    |&gt; shuffle()
    |&gt; split(length(set_of_cards) * 2)
  end
end</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="279633" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/trying-to-implement-war-card-game-in-elixir/54134/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-279633" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="279633"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="279796" data-post-id="279796">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zoedsoupe" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zoedsoupe/120/25602_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zoedsoupe
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>That’s a good solution! I like it, although it’s still failing on test cases. I’m trying to understand if those tests could wrong</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="279796" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/trying-to-implement-war-card-game-in-elixir/54134/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-279796" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="279796"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/54134/load_more?page=3">Load more posts (21 remaining)</a>
</div></template></turbo-stream>