<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Unruly Rambling - algorithm tag</title>
  <link>http://www.shoesobjects.com/blog/tags/algorithm/</link>
  <description>My thoughts on software, technology, and life in general</description>
  <language>en</language>
  <copyright>Mike Shoemaker</copyright>
  <lastBuildDate>Sun, 31 Jan 2010 17:47:37 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>How would you write a shuffle algorithm?</title>
    <link>http://www.shoesobjects.com/blog/2005/12/01/how_would_you_write_a_shuffle_algorithm.html</link>
    
      
        <description>
          &lt;p&gt; As I&#039;m beginning to write my card game application, I&#039;ve approached the unit test where I need to shuffle the deck.  I&#039;ve implemented it based on Knuth&#039;s Shuffle algorithm.  My question is, what are some clever ways that other programmers have implemented it?   &lt;/p&gt;
&lt;p&gt; My current implementation works like this.    &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Put all 52 cards in an array&lt;/li&gt;
    &lt;li&gt;For Loop starting at element 51, working backwards&lt;/li&gt;
    &lt;li&gt;Generate random number between 0 and loop element index&lt;/li&gt;
    &lt;li&gt;Swap current element card with the element at the random index generated in previous step&lt;/li&gt;
    &lt;li&gt;Finish when loop index reaches the zero element.  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt; Delima with current implementation &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Is there a bias with generating a random number between 0 and the loop index?  I&#039;m doing so with java.util.Random&lt;/li&gt;
    &lt;li&gt;Would multiple shuffle iterations over the deck solve this?&lt;/li&gt;
    &lt;li&gt;Is it worth refactoring the shuffle algorithm to use the strategy pattern so I can have multiple implementations of shuffle?  After all, this is a simple command line game, not Harrah&#039;s next killer online gambling app.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
        </description>
      
      
    
    
    
    <category>java</category>
    
    <comments>http://www.shoesobjects.com/blog/2005/12/01/how_would_you_write_a_shuffle_algorithm.html#comments</comments>
    <guid isPermaLink="true">http://www.shoesobjects.com/blog/2005/12/01/how_would_you_write_a_shuffle_algorithm.html</guid>
    <pubDate>Fri, 02 Dec 2005 05:59:32 GMT</pubDate>
  </item>
  
  <item>
    <title>Too Little Time To Shuffle</title>
    <link>http://www.shoesobjects.com/blog/2005/11/29/too_little_time_to_shuffle.html</link>
    
      
        <description>
          &lt;p&gt; As Christmas grows near, my &lt;a href=&#034;http://www.shoesobjects.com/blog/2005/08/23/1124819371353.html&#034;&gt;Organizational Behavior course&lt;/a&gt; is coming to an end.  I have enjoyed the class tremendously but I haven&#039;t had the opportunity to tinker around with new technology or complete any fun programming projects.  I did say fun so work doesn&#039;t count.  Not having this needed outlet puts a serious damper on my energy level as well as professional motivation. Now that things are starting to slow down a bit, what will I do?&lt;/p&gt;
&lt;p&gt; For the past several months I&#039;ve had poker on my mind and have considered writing a game in Java.  My friends and I play a card game call &lt;a target=&#034;_blank&#034; href=&#034;http://en.wikipedia.org/wiki/Bourr%C3%A9&#034;&gt;Bourre&lt;/a&gt; ad nauseum.   Sometimes we play 20+ rounds in an evening which equates to 4 hours or so. Bourre is a trick based card game similar to spades(I&#039;ve never played spades but I&#039;ve heard people compare the two).  A typical Bourre hand is played like this.  The dealer deals 5 cards to each player.  After dealing, the dealer is allowed to flip up one of his cards to determine the trump suite.  This card is visible to all players.  At this point players decide if they are in or out.  They call this out one by one moving clockwise around the table.  A player can say in, out, or check.  Once a single player is in, the check option is no longer available.  Players that drop are out for the duration of this particular game which could be many hands.  Players that remain in are allowed to draw up to five of their cards by discarding a like number.  Once the draw is complete, the player to the left of the dealer starts the game by leading a card.  The next player must throw a card of the same suite if he has one, otherwise he can &amp;quot;throw off&amp;quot; another suit or &amp;quot;trump&amp;quot; the played suite.  The highest card of the led suite wins the trick.  If someone trumps the led suite, the trump card beats all cards in any other suite.   Any player not winning a single trick must match the pot.  Any player winning three tricks wins the pot.  If no one gets 3 tricks to win the game another game is dealt and lather, rinse, and repeat cycle continues.  It&#039;s an addicting game that is a lot of fun to play.  &lt;/p&gt;
&lt;p&gt; My first attempt will be a command line version of the game.  Not sure of the chances of actually completing it, but I would really like to.  With a little luck and inspiration, maybe I&#039;ll be able to recruit someone to work on a rudimentary user interface down the road.  At any rate, I better search for my &lt;a href=&#034;http://www.amazon.com/gp/product/0201485419/002-8135991-3378460?v=glance&amp;amp;n=283155&amp;amp;v=glance&#034;&gt;The Art of Computer Programming&lt;/a&gt; books by &lt;a href=&#034;http://en.wikipedia.org/wiki/Donald_Knuth&#034;&gt;Donald Knuth&lt;/a&gt; to brush up on a shuffle algorithm.  If I find any typos I promise to share the $2.56 finder fee.   &lt;/p&gt;
        </description>
      
      
    
    
    
    <category>java</category>
    
    <comments>http://www.shoesobjects.com/blog/2005/11/29/too_little_time_to_shuffle.html#comments</comments>
    <guid isPermaLink="true">http://www.shoesobjects.com/blog/2005/11/29/too_little_time_to_shuffle.html</guid>
    <pubDate>Wed, 30 Nov 2005 05:54:37 GMT</pubDate>
  </item>
  
  </channel>
</rss>

