title: Modeling the card game War in Ruby and keep getting an infinite loop. Could someone help me understand what's going wrong in my control flow
body: <p>I'm new to Ruby and only started a few weeks ago.  I'm trying to create an algorithm that simulates how the game is played, but I'm getting stuck in an infinite loop.  Something is wrong with my control flow and I just don't see it.  Right now, I'm not adding in the loop for the war part and just trying to take the card out of the end of the array and put it back at the beginning.  Also, just to note, I don't use .shuffle! because we were told not to.  This is part of my algorithms class.  Also, I'm not cheating, we were told to use Stack Overflow and other resources.  </p>
  
  <p>Can someone help me understand where I'm going wrong?  Thanks!</p>
  
  <pre><code>deck = (2..14).to_a*4
  
  
  deck.sort! {|a, b| rand &lt;=&gt; rand}
  player1 = deck.values_at(0..25)
  player2 = deck.values_at(26..51)
  print "Player 1's cards: #{player1}"
  print "Player 2's cards: #{player2}"
  
  hand_count = 0
  
  until player1.count == 52 || player2.count == 52
      hand_count += 1
      state = player1[-1] &lt;=&gt; player2[-1]
      if state == -1
          player2.unshift(player2.pop)
          player2.unshift(player1.pop)
          puts "Player 2 won hand #{hand_count}"
      elsif state == 1
          player1.unshift(player1.pop)
          player1.unshift(player2.pop)
          puts "Player 1 won hand #{hand_count}"
      else
          player2.unshift(player2.pop)
          player1.unshift(player1.pop)
          puts "It's a tie"
      end
  end
  
  puts "Player 1 wins" if player1.length == 52
  puts "Player 2 wins" if player2.length == 52
  </code></pre>