April 6--an exercise on the number of algorithms--Poker Shuffle

Source: Internet
Author: User
Tags shuffle

Poker

1. Define an array that holds 1-52 (52 cards, no big, Little King)
Of these, 1 means that the a,2 of spades means that the 2...,13 of spades means the spades K, and 14 means the Red peach ...)

2. Randomly arrange the array

3. Then average the cards to 4 players (divided into 4 arrays, according to the rules of the licensing)

4. Sort the output of each player's poker (according to the suit: spades, Hearts, clubs, squares; then size)

<!    DOCTYPE html>varArr=[]; //1. Store 1-52 cards in arr array         for(vari=1;i<=52;i++) {Arr[arr.length]=i; }        //2. ShuffleArr.sort (function(){                returnMath.random ()-0.5;        }); //3. Define the player array        varplayers=[];  for(vari=0;i<4;i++) {Players[i]=[]; }        //4. Licensing         for(vari=0;i<52;i++){            //0,4,8            //1,5,9Players[i%4].push (Arr[i]); }        //5. Player Sort         for(vari=0;i<4;i++) {Players[i].sort (function(A, b) {returnA-b;        }); }        //Console.log (arr);        //Console.log (players);        //6. Output        varTypes=["Spades", "Hearts", "Plum", "squares"]; varnums=["A", "2", "3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", "K"];  for(vari=0;i<4;i++) {Console.log (' Player ' + (i+1) + "card:");  for(varj=0;j<13;j++){                    varn=Players[i][j]; varType=math.floor ((n-1)/13)//n-1 corresponding subscript 0123varsno= (n-1)%13;//n-1 corresponding subscript 0-13Console.log (types[type]+Nums[sno]); } console.log (' ========== '); }    </script>

April 6--an exercise on the number of algorithms--Poker Shuffle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.